Nickname contains the beginning of the email address instead of the provided username

Hi all,

I have turned on the “requires username” switch in the database - Username-Password-Authentication settings. Auth0 indeed asks the user for a username when signing up now.

However, when fetching the user using the Angular SDK, the nickname on the user object does not contain this username, instead it contains the first part of the email address. For example:

{
    email: "fakemail@test.com"
    email_verified: false
    name: "fakemail@test.com"
    nickname: "fakemail"
    picture: "...."
    sub: "...."
    updated_at: "...."
}

Instead of the “fakemail”, I would have expected the provided username.

How can I add this to the nickname field / add the username to the user object?
I have been playing around with the Auth0 Rules but did not manage to create the expected behaviour.

Help would be much appreciated!

1 Like

Hi @jodi,

Welcome to the Auth0 Community!

You should see a username property, like this:

"username": "ExampleUser1"

The nickname claim is a bit different. It is defined as follows:

Casual name of the End-User that may or may not be the same as the given_name. For instance, a nickname value of Mike might be returned alongside a given_name value of Michael.

In this case, it is a truncated version of the name attribute.

Hi @dan.woda

Thanks for the response! Unfortunately I do not see a username property in the response I get from the $user call in angular.

Any idea how to get it there?

Thanks!
Jodi

Do you see it in the user’s JSON object in the Auth0 dashboard?

@dan.woda,

I do see it in the auth0 user dashboard. It is displayed correctly there :slight_smile:

It turns out that username is not a standard OIDC claim, and you must add it to the token in an action or rule. This post covers it:

2 Likes

@dan.woda

Thanks, works perfectly!!

Quick note for other people looking for the same solution:

function (user, context, callback) { 
  context.idToken['https://mynamespace/username'] = user.username; 
  callback(null, user, context);  
}

the “mynamespace” in the above code block is not allowed to be any auth0.com, webtask.io or webtask.run domain.

1 Like

How do you set username using action?

Thanks for sharing this tip!

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