accessTokenExpires in "account" is always "null" despite the response
See original GitHub issueYour question
Why accessTokenExpires
may be always null
?
Even when there’s a clearly stated expires_in
in response and exp
in token?
What are you trying to do I’m using custom oAuth provider.
On token request I get response like this:
{
"access_token": <id_token_here>,
"refresh_token": <refresh_token_here>,
"id_token": <id_token_here>,
"token_type": "Bearer",
"expires_in": 7199
}
But in jwt-callback in account
parameter I always get this:
{
provider: <provider>,
type: 'oauth',
id: <id>,
refreshToken: <refresh_token>,
accessToken: <access_token>,
accessTokenExpires: null
}
Question is: why?
Sadly I can’t provide a repo for reproduction due to privacy policy. Nevertheless, count on your support!
My nextauth config:
{
providers: [
{
id: <provider_id>,
name: <provider_name>,
type: 'oauth',
version: '2.0',
scope: 'profile openid email',
params: { grant_type: 'authorization_code' },
accessTokenUrl: getAccessTokenUrl,
requestTokenUrl: getAccessTokenUrl,
authorizationUrl: `${getAccessCodeUrl}?response_type=code`,
profileUrl: getProfileUtl,
profile: async (profile) => {
return {
id: profile.uid,
role: profile.role,
name: profile.displayName,
email: profile.mail
};
},
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET
}
],
pages: {
signIn: '/auth'
},
events: {},
callbacks: {
session: async (_session, token) => {
return { ...token };
},
jwt: async (token, user, account, profile) => {
if (account && user) {
return {
accessToken: account.accessToken,
accessTokenExpires: Date.now() + account.expires_in * 1000,
refreshToken: account.refreshToken
};
}
if (Date.now() < token.accessTokenExpires || !token.accessTokenExpires) return token;
return refreshAccessToken(token);
}
}
};
Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
- Found the documentation helpful
- Found documentation but was incomplete
- Could not find relevant documentation
- Found the example project helpful
- Did not find the example project helpful
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - ADB2C - Handling the "Null user was passed in ...
The problem is that when the app is restarted, the user remains authenticated through the ADB2C cookie, but confidentialClientApplication.
Read more >Credentials Provider Refresh Token Rotation - jwt callback ...
So my access token gets refreshed as long as I do client-side requests, but if I fetch all my data server-side my session...
Read more >Token returns null - ServiceNow Community
In a scoped application, I am using the details stored in the Application Registry [oauth_entity] to generate access and refresh token.
Read more >Refresh Tokens in ASP.NET Core Web Api - The Blinking Caret
When you use the ASP.NET Core authentication middleware for authenticating the user using JWT it will return a 401 response to an expired...
Read more >Persistent login in React using refresh token rotation
When an access token expires, a refresh token can be used to get a new access token without entering login credentials again.
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 Free
Top 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
Yes, that did the trick. Sorry for bothering. Thank you!
No problem! Happy that it worked out 🙂