Twitter nickname is not the same as screen_name

My Twitter handle is @edent. If I login with Auth0, I see:

  'nickname' => 'Terence Eden',
  'name' => 'Terence Eden',

I would expect my “nickname” to be the same as my screen_name.

If I log in with GitHub (Where I am also @edent) I get:

  'nickname' => 'edent',
  'name' => 'Terence Eden',

I’m using the PHP library, if that makes a difference?

use Auth0\SDK\Auth0;

$auth0 = new Auth0([
	'domain' =>        AUTH0_DOMAIN,
	'client_id' =>     AUTH0_CLIENT_ID,
	'client_secret' => AUTH0_CLIENT_SECRET,
	'redirect_uri' =>  AUTH0_CALLBACK,
	'audience' =>      AUTH0_AUDIENCE,
	'scope' =>        'openid profile',
	'persist_id_token' =>      true,
	'persist_access_token' =>  true,
	'persist_refresh_token' => true,
]);
if (!$userInfo) {
	$auth0->login();
} else {
	var_export($userInfo);
}

:wave: if you want the Twitter user’s handle you need to call the API endpoint in order to retrieve it, screen_name . This can be accomplished using GET users/show (https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-show,) which returns a bunch of information including the screen_name (being the user’s handle). We can call the endpoint by using the access token we get as described here

https://auth0.com/docs/connections/social/twitter#6-access-twitter-api

In order to get a Twitter Access Token, you have to retrieve the full user's profile, using the Auth0 Management API, and extract the Access Token from the response.

You can find more information about the Twitter user object here: User object | Docs | Twitter Developer Platform

1 Like

I understand how to use the Twitter API. What I don’t understand is why there is an inconsistency.

Using Auth0 with GitHub, WordPress, and Google all return a username as part of the “nickname” field. Twitter doesn’t. Why is that?

So upon first glance it seems that something may have changed in the Twitter API and we might need to adjust - we’ll look into that to see what’s going on

1 Like

So we have the following example which may help you out?

https://auth0.com/docs/connections/pass-parameters-to-idps#example-twitter

That doesn’t help. I’m sorry, I’m not explaining myself clearly. Let me try again.

  • I am edent on GitHub. When I log in using Auth0, the nickname is set to edent.
  • I am edent on WordPress. When I log in using Auth0, the nickname is set to edent.
  • I am edent on Google. When I log in using Auth0, the nickname is set to edent.
  • I am edent on Twitter. When I log in using Auth0, the nickname is set to Terence Eden.

I don’t want to do yet another API call. I just want the user’s Twitter screen_name to appear in the nickname. Just like it does on other providers.

Or have I misunderstood something about how Auth0 works?

1 Like

Hi @edent.
I’m guessing this was either an oversight or that the profile’s screen_name wasn’t available when this connection type was implemented in Auth0. I will report this internally so hopefully this will eventually get fixed.

In the meantime, a good workaround is to create the following rule:

function (user, context, callback) {
  // Put the user's screen_name as the nickname
  // for Twitter connections
  if (context.connection === 'twitter' && user.screen_name) {
    user.nickname = user.screen_name;
  }
  callback(null, user, context);
}

This will modify the information that applications get (either from the ID Token or from the /userinfo endpoint), but will not modify the actual user profile stored. Keep that in mind that if you use /api/v2/users or the dashboard to get the full user profile will still see the full name in the nickname property.

2 Likes

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

This works easily enough but this is pretty inconvenient. I would have expected this to be addressed by now, but seems to be an issue over a year later.

1 Like