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.
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.