auth0auth0-lock

How to get Facebook user id from Auth0-Lock SSO Authentication


I'm using Auth0-Lock for authenticating a user. But it seems that the response data from Auth0 did not include Facebook user_id. I want to get user_id because I need it to show user's profile URL in my app, like this: www.facebook.com/{user_id}.

{
"sub": "facebook|1613270415401150",
"given_name": "Steve",
"family_name": "Giáp",
"nickname": "hgbk.it",
"name": "Steve Giáp",
"picture": "https://graph.facebook.com/v2.5/1613270415401150/picture?width=720",
"gender": "male",
"locale": "en-GB",
"updated_at": "2018-10-09T04:25:12.921Z"
}

The Id from sub or picture are not related to user_id.


Solution

  • The user_id that Auth0 uses is the id that is provided by the identity provider and in the case of Facebook they are now app-scoped. Therefore, the user_id is not the user id of the user, but rather an identifier for the user for this specific application. As per Facebook docs The id of this person's user account. This ID is unique to each app and cannot be used across different apps. This is the id that Auth0 uses as the user_id, following the pipe, e.g. facebook|<id from Facebook>. I believe you used to be able to use that id to see a person's public profile, but Facebook has since deprecated providing the username.