question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

accessTokenExpires in "account" is always "null" despite the response

See original GitHub issue

Your 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
St-Permiakovcommented, Mar 16, 2021

Yes, that did the trick. Sorry for bothering. Thank you!

0reactions
balazsorban44commented, Mar 16, 2021

No problem! Happy that it worked out 🙂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found