Access profile username from Flask/Python

Hello,

I’m very new to Auth0 and Oauth, and i’ve just implemented the basic python quick start into my app. In my database I set it to ask for a username. In the JWT I recieve after login there is not key for this username. So, I would like to know how to access this username, is there a scope for it that im missing or do you have to make a seperate API call? I’ve already used the scopes openid, profile, and email but that hasn’t worked.

Thanks in advance.

Hi @Zuma206,

Welcome to the Auth0 Community!

Unfortunately, the Username attribute is not part of the list of standard claims returned from the openid profile email scopes.

In this scenario, you will need to append the username as a custom claim to the ID token using an Auth0 Post-Login Action.. See below for an example.

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/username`, event.user.username);
  }
}

After you have included this action into the auth pipeline, you will be able to get the username in the ID Token.

Please let me know if there’s anything else I can do to help.

Thanks.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.