auth0 / auth0-react

Auth0 SDK for React Single Page Applications (SPA)
MIT License
866 stars 252 forks source link

api.accessToken.addScope is not working #786

Open victorcopque opened 1 month ago

victorcopque commented 1 month ago

Checklist

Description

In the Actions flow, if you want to modify the accessToken using api.accessToken.addScope, the token remais the same. Action that I used as example:

exports.onExecutePostLogin = async (event, api) => {
    const appMetadata = event.user.app_metadata;
    var permissions = appMetadata?.authorization?.permissions;

    var requestedScopes = event.request.body.scope || event.request.query.scope;
    var parsedScopes = requestedScopes.split(" ");

    var allScopes = parsedScopes.concat(permissions);

    allScopes.forEach(scope => api.accessToken.addScope(scope));
};

NOTE: if you run the "same code" in Auth Pipeline > Rules, it works! 🎉

Reproduction

  1. Create a Custom Action
  2. Adds the new action created in the Post Login Flow
  3. Fill the login form with your credentials
  4. Submit Form

So if you inspect the token retrieved after login, the scopes remains unchanged

Additional context

No response

auth0-react version

2.2.4

React version

18.2.0

Which browsers have you tested in?

Chrome