nextjs-auth0 icon indicating copy to clipboard operation
nextjs-auth0 copied to clipboard

Better support for refresh tokens

Open sandrinodm opened this issue 7 years ago • 2 comments

Describe the problem you'd like to have solved

We now have the capability to store a refresh_token in the session using storeRefreshToken. However, as a developer I currently need to do a lot of heavy lifting to put this to good use:

  • I use the access_token
  • When the API I'm calling returns a 401, I can assume that the token is expired and use the refresh token instead.
  • I need to perform the refresh token exchange myself
  • I don't really have a capability to update the access_token in the session

Describe the ideal solution

Ideally I would be able to retrieve an access token from the session and everything is handled for me. If the token is valid, return that. If the token is missing a scope, return null. If the token is for an other audience, return null. If the token is expired, renew it, ...

const { user } = await auth0.getSession(req, res);
const accessToken = auth0.getAccessToken({
  scope: 'read:calendar',
  audience: 'https://myapp.com/api'
});

sandrinodm avatar Sep 24 '19 16:09 sandrinodm

Any news about this ? Is there a way to update the session with the new access_token generated with a refresh_token ?

abathellier avatar Oct 09 '19 14:10 abathellier

Released in v0.8.0 👋

sandrinodm avatar Jan 08 '20 14:01 sandrinodm