Search code examples
c#asp.net-web-apioauth

Is there any way to check if oauth token is expired or not?


I am accessing web api using oauth token.

Token expires after 1 hour. But I want to add functionality to generate new token when it expires.

I found that in case of expired token it sends StatusCode as unauthorized.

Please let me know if its the only statuscode which tells about expiration of token.


Solution

  • The easiest way is to just try to call the service with it. It will reject it if it is expired and then you can request a new one.

    You can also keep the time you received the token and use the expires_in to calculate when it will approximately expire. Then you request a new token before making a new request after the expiration date.