javascriptreactjsauth0userinfo

How to get user info in a react app which uses auth0 for authentication


I was trying to get user info from login using twitter in auth0. auth0 provides userInfo api for getting users details, but it is just returning an object with a key sub (like this - {"sub":"twitter|XXXXXXXXX"} ). As per the documentation provided, we should get the name, picture, nickname etc, in my case only one sub is returning. I wanted to know how the details of user can be fetched in auth0.

edit - providing the configs used.

auth0 = new auth0.WebAuth({
        domain: AUTH_CONFIG.domain,
        clientID: AUTH_CONFIG.clientId,
        redirectUri: AUTH_CONFIG.callbackUrl,
        audience: `https://${AUTH_CONFIG.domain}/userinfo`,
        responseType: 'token id_token',
        scope: 'openid'
    });

Solution

  • The question does not offer any details on how you are making the authentication request with Twitter social connection. At a minimum, suggest that you try adding scope: openid profile email to your authentication request. That will ensure the id_token returned contains all OIDC conformant user profile attributes (claims).

    Please see the documentation for details.

    If you visit the auth0 dashboard social connections you can see what twitter returns to Auth0. With OIDC conformance enabled you can expect to see at least basic info like sub (user id), name, and picture. Screenshot below - please make sure you did tick the checkbox for Basic Profile user consent.

    enter image description here