Identity Server 4 Access Token Lifetime is expiring beyond its lifetime

Viewed 920

I have set the lifetime of my access and refresh token for testing. Now, I'm, wondering why the access token did not follow its lifetime and is still valid until the refresh token lifetime? I'm not sure if I set it right but here's how I configure the token lifetime:

            var accessTokenLifetime = 300;
            var absoluteRefreshTokenLifetime = 600;

            resultClient = new Client
            {
                AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                AllowOfflineAccess = true,
                IdentityTokenLifetime = accessTokenLifetime,
                AccessTokenLifetime = accessTokenLifetime,
                UpdateAccessTokenClaimsOnRefresh = true,
                RefreshTokenUsage = TokenUsage.OneTimeOnly,
                RefreshTokenExpiration = TokenExpiration.Absolute,
                AbsoluteRefreshTokenLifetime = absoluteRefreshTokenLifetime
            };

Note: I removed some of the properties there.

Any thoughts?

1 Answers

The clients contains a 5 minute ClockSkew by default to support cases where the clocks in the different services are different.

You can set it in the Startup.ConfigureServices in your client applications, like this example to accept 1 minute skew. You can also set it to Zero if you like.

.AddMyJwtBearer(options =>
{
    options.TokenValidationParameters.ClockSkew = TimeSpan.FromMinutes(1);
    ...
Related