Vahe
Vahe

Reputation: 75

How to add refresh token expiration date to token endpoint response?

I need to have refresh token expiration date on client side. By default Identity Server returns access token expiration date in response. I can make a request with expired refresh token and handle not authorized response by requesting user to login again, but it's another round trip which can be skipped if I have refresh token expiration date on client side.In this case we can check refresh token on client side and if it's expired then user will be redirected to login page.

Upvotes: 1

Views: 377

Answers (2)

d_f
d_f

Reputation: 4869

In general scenario you just don't need it. Look: once your access token expires, you get a new pair where the fresh refresh token is valid for a month again (the default value, you are free to enlarge it even more). And so on and so on. So the another round trip occurs when your app has not been used for a really long-long time. And most likely that's not so bad.

But if you still like to customize the response, it's easy.

In your case there will be something like:

public Task ValidateAsync(CustomTokenRequestValidationContext context)
{
    var ttl = context.Result.ValidatedRequest.Client.AbsoluteRefreshTokenLifetime;
    context.Result.CustomResponse = 
        new Dictionary<string, object>{{"refresh_interval", ttl}};
    return Task.CompletedTask;
}

Upvotes: 1

Abdul Muheet Shaikh
Abdul Muheet Shaikh

Reputation: 21

What you can do is compare the expiration time(convert it to universal time) with current time and you'll come to know the refresh token is expired or not, no need to make another call for finding it out.

Upvotes: 0

Related Questions