I came across this thread with a very similar issue and I’m still confused:
If I have this in pages/api/auth/[...auth0].ts
export default handleAuth({
async login(req, res) {
try {
await handleLogin(req, res, {
authorizationParams: {
audience: 'https://[redacted]', // or AUTH0_AUDIENCE
// Add the `offline_access` scope to also get a Refresh Token
scope: 'openid profile email offline_access do:anything' // or AUTH0_SCOPE
}
});
} catch (error) {
res.status(error.status || 400).end(error.message);
}
}
});
And then later inside a getServerSideProps
call
const { accessToken} = await getAccessToken(context.req, context.res, {
scopes: ['openid', 'profile', 'email', 'offline_access', 'do:anything']
});
I get this error
AccessTokenError: Could not retrieve an access token with scopes "openid profile email offline_access do:anything". The user will need to sign in again.
But if I remove the scopes
parameter above, it works AND the server indicates that the JWT has scope: 'openid profile email do:anything'
. Note that my custom do:anything
scope is there, but offline_access
is missing.
Can someone help me understand what’s going on and which scopes should be used in which calls? Thanks!