Username is not populating in auth0 drupal module

Hi,

We are using auth0 drupal 8 modules in our site but when user register in auth0 and then user gets redirected to the drupal site on auth0/callback url with state and token.

Then callback to user info is made but api is not returning the username. please let us know how to get username in user api.

1 Like

Hi and Welcome to Auth0 Community! @moneesh.koundal :tada:

  • username is not a standard OIDC claim so for a flow that is conformant to OIDC the username attribute won’t be automatically included neither in an ID token nor in the /userinfo response (https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims ).
  • in the scenario you described you likely are performing an OIDC authentication request and an OAuth 2.0 authorization request for your custom API ( audience parameter) at the same time. In other words, you likely received an ID token and an access token .

However, the above now requires an additional network request at the API level so you may want to review if explicitly including the required information in the access token as custom claims presents a better solution to your scenario. You can include namespaced custom claims in issued access tokens through the use of rules (https://auth0.com/docs/scopes/current/sample-use-cases#add-custom-claims-to-a-token ).

Given username is not a standard claim, if you want to include that information in an ID token you will require a custom claim or map that to a standard claim.

1 Like

FYI - that same (or similar Drupal related) question came up just two days ago, though slightly different approach:

A code snippet for the custom claim approach is here:

1 Like