Best practice to handle expired refresh tokens?
See original GitHub issueHello, I am using Azure AD as the auth provider and there is 24 hours lifetime of the refresh token. After 24 hours I am getting the following error in console log:
Does anyone have an advice how to handle this error? What is the best practice?
Currently I am thinking about handling it when access_token expires in this event by doing signOut.
mgr.events.addAccessTokenExpired(function () {
log("token expired");
chrome.storage.local.get(['user'], (data) => {
client.useRefreshToken({state: data["user"], timeoutInSeconds: 5 }).then(user => {
console.log("refreshedToken user: ", user);
mgr.storeUser(new oidc.User(user));
}).catch(err => {
// possible fail here is that the lifetime of the refreshToken ended.
// for AzureAD it is 24 hours for SPA. 90 days for all other apps.
console.error(err);
globalThis.signOut();
});
});
});
I feel like this is not the best UX for the users to be automatically signed out every 24 hours. Is there a better way?
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Token Best Practices - Auth0
To avoid accumulating obsolete refresh tokens, even though the refresh token limit removes the oldest token first, we recommend you configure refresh token...
Read more >OAuth Refresh Token Best Practice [closed] - Stack Overflow
It should change when a new access token is issued using the refresh token, however, the expiry date should remains the same. When...
Read more >Antipattern: Set a long expiration time for OAuth tokens
Set the expiration time for refresh tokens in such a way that it is valid for a little longer period than the access...
Read more >10 OAuth Token Expiration Best Practices - CLIMB
Refresh tokens, on the other hand, are used to generate new access tokens when the old one expires. Since refresh tokens are not...
Read more >Refresh access tokens - Okta Developer
The default value for the refresh token lifetime ( refreshTokenLifetimeMinutes ) for an Authorization Server actions object is Unlimited, but expires every ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Alino, an expired
refresh_token
doesn’t mean theuser's session
has expired too. You don’t necessarily have to re-log in.What the blue box means:
Usually the flow of ODIC Auth code + PKCE is as follow:
access_token
to call your private APIsaccess_token
is about to expire, an ajax call will be made with therefresh_token
to get complete new tokensrefresh_token
expire, you are stuck. You cannot ask for new tokens and there is no way to authenticate the user back without having him to interact somehow.There is a technique though, where you could be using an hidden iframe that would navigate to the OP and re-use the
session cookie
. Allowing you to get tokens in returns, if a user’s session was still active. This is ideal (in theory) because completely transparent for the user.But web browsers like Safari are now using privacy features (ITP - Intelligent Tracking Prevention) that prevents third party cookies to be sent, making this technique useless (ie. my-app.com cannot use cookies from my-op.com even in a child frame). If you want to use cookies from my-op.com then you have to be on my-op.com (top frame).
So the only solution is to navigate to the OP from the top level frame instead of the iframe:
refresh_token
expiration=> no user interaction needed (just a back and forth, like if your app was refreshed) => regarding the UX, user’s would have to be prompted before the redirect occurs otherwise there is a risk for them to loose what they were doing
Understood, thank you. I have noticed the cookie inside the auth popups that are being opened when using
chrome.identity.launchWebAuthFlow
That brings me to the idea that I am going to testchrome.identity.launchWebAuthFlow
with non interactive mode perhaps, to see if that renews the refresh_token.EDIT: I have tested it, and it seems to work. But I am going to test for few more days.