We have an existing application use NextAuth to communicate with Okta. This is all working fine, we've just added an API which needs the Okta Access Token, we've used the JWT callback in NextAuth to grab the access token from the account object, and add that to the NextAuth session.
This is all working fine, we can grab the access token from the session and pass that to the API and is all good, the API validates the access token and all is fine. But, we sometimes come back to the session and the call to the API fails because it can not validate the access token as it has expired.
I'm looking at the NextAuth documentation for rotating a refresh token and I see that Okta has an end-point for getting a new refresh token. That all seems to make sense, the problem is, looking at what the JWT callback in NextAuth returns, I don't get a refresh token, these are the props returned by the Okta provider. We get an access token, and an ID token (they do contain different values) but we don't get a refresh token returned.
I see reference to offline_access scope with regards to refresh tokens, do we need to set this in our call for the Okta provider? If so, how? Otherwise, has anyone managed to use the Okta Provider in NextAuth and fixed the expired access token issue?
{
token: {
name: ...,
email: ...,
picture: .,
sub: ...
},
user: {
id: ..,
name: ...,
email: ...,
image: undefined
},
account: {
provider: 'okta',
type: 'oauth',
providerAccountId: ...,
token_type: 'Bearer',
expires_at: ...,
access_token: ...,
scope: ...,
id_token: ...
},
profile: {
sub: ...,
name: ...,
email: ...,
ver: ...,
iss: ...,
aud: ...,
iat: ...,
exp: ...,
jti: ...,
amr: [ ... ],
idp: ...,
preferred_username: ...,
auth_time: ...,
at_hash: ...
},
isNewUser: undefined
}