3

Refresh token works fine for 2 to 3 days but after few days it stops working.

On Authentication call for

grant_type = refresh_token

IIS return Bad request 400 with error message

{error : "invalid_grant"}

temporary solution

it works fine by restarting/recycling API instance on IIS.

Unable to find what is the issue with the IIS or the Owin why it works fine for few days while i have set an expiry time of 30 days for the refresh token.

This is the code used for refresh token

    var token = new RefreshToken()
    {
        RefreshTokenId = refreshTokenId,
        ClientId = clientid,
        UserEmail = context.Ticket.Identity.Name != clientid ? context.Ticket.Identity.Name : null,
        IssuedOn = DateTime.UtcNow,
        ExpiresOn = DateTime.UtcNow.AddDays(30)
    };

    context.Ticket.Properties.IssuedUtc = token.IssuedOn;
    context.Ticket.Properties.ExpiresUtc = token.ExpiresOn;

    token.ProtectedTicket = context.SerializeTicket();

I will be thankful for Any help regarding this issue.

Ghulam Mohayudin
  • 1,093
  • 10
  • 18

1 Answers1

0

IIS by default recycles your app pool by calling a garbage collector to clear the memory on every 20 minutes, So if you store the refresh tokens in the ram (ex: a static dictionary or whatever data structure) they will be cleaned after the recycling. That's why the refresh tokens will no longer be valid even if their life time is longer.

Hosam.Yousof
  • 107
  • 9