Username displayed in Drupal admin not correct

Hello,
For some reasons, the username entered when signing up is not the one displayed in Drupal admin (/admin/people) “Username” column. Instead, it its displaying the beginning of the user’s email address. This is a little confusing. Any idea how to get the proper username (entered by the user when signing up) there?
Thanks!

I don’t know Drupal so I don’t know from which JWT claim (attribute) it takes the username value from. I think it also depends which Drupal OAuth/OIDC plugin you’re using.
My assumption is that it’s taking it from the name attribute/claim, while the username you user in the signup is in the username claim/attribute.

It’s very similar to the question here:


You should use a Rule (as shown in the linked threads, but slightly adjusted) to put the username value as the user name.

Untested, but should be like this:

function (user, context, callback) {

  if (user.name !== user.username) {
    var ManagementClient = require('auth0@2.9.1').ManagementClient;
    var management = new ManagementClient({
      token: auth0.accessToken,
      domain: auth0.domain
    });

    var params = { id: user.user_id };
    var data = { nickname : user.username };

    management.users.update(params, data, function (err, users) {
      if (err) {
        //handle err
      }
      console.log(user);
      callback(null, user, context);
    });
  }

  callback(null, user, context);
}

Hello,
I tried to test this rule and got this error:
"The script has errors. Do you want to save it anyway?

  1. Line 8: Confusing use of ‘!’."
    Could you please fix this line of code?

It also recommends to remove the semi-column on line 25 and 28 to this:
}

callback(null, user, context);
}
Thanks!

Yes, that should be

if (user.name !== user.username) {

of course

OK, let me try that. The name of the rule doesn’t matter, right?

I trie it (using “Try this rule” button) and this is the Output message:

ERROR: Invalid response code from the auth0-sandbox: HTTP 400. Unexpected token function

There was one error with the package version, I corrected it above.

var ManagementClient = require('auth0@2.9.1').ManagementClient;

Code works fine for me.

You corrected it on my codes? Or I should do the correction as well?

No, I corrected it in my posting above, not on yours.

OK, let me do that as well.

OK, no more error. I need to try to create a new user with username and see if it implements the same in Drupal.
Also, when you create a rule, it applies to all your Apps? Because, I don’t see where to select which app to apply that rule to.

“We’re sorry, something went wrong when attempting to sign up.” This is what I get when trying to sign up.

Need to check the logs. Dashboard > Logs > Search, for more details.

Ok, let me check on that.

Type

Failed Signup

Description

The user already exists.

Connection

Username-Password-Authentication

It says user already exist. Let me try with a different email.

It looks like I’m not getting the confirmation email that I need to click on to complete the signup process. Let me try with another email and see.

email just arrives. let me continue the testings.

Yes, a Rule runs for all apps. If you don’t want to execute its logic for all, add a if-statement like:

if (context.clientID === 'APP_CLIENT_ID') ...

Well, it still now displaying in Drupal the username that I entered when signing up. Instead, it’s displaying the characters before the “@” of the user’s email.

Earlier, I think that you mentioned another post with issue similar to mine. Any idea if they found a working solution?