# Unable to retrieve username

**URL:** <https://community.auth0.com/t/unable-to-retrieve-username/112638>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [August 2, 2023, 1:32am UTC](https://community.auth0.com/t/unable-to-retrieve-username/112638 "2023-08-02T01:32:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koki-1205](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Koki-1205](https://community.auth0.com/u/Koki-1205)\
**Post date:** [August 2, 2023, 1:32am UTC](https://community.auth0.com/t/unable-to-retrieve-username/112638/1 "2023-08-02T01:32:33Z")

</div>

I am building a sns in django while researching.

I am trying to get the username, but the information I get does not include the username.

I am not sure I understand all the code, is this a problem with the code?

```auto
def login(request) :    
    url_params = urlencode({
        'response_type': 'code',
        'client_id': auth0_client_id,
        'redirect_uri': auth0_callback,
        'scope': 'openid profile email',
    })
    
    auth_url = f'https://{auth0_domain}/authorize?{url_params}'
    return redirect(auth_url)

```

```auto
def callback(request) :
    code = request.GET.get('code')
    if code :
        data = {
            'client_id': auth0_client_id,
            'client_secret': auth0_client_secret,
            'redirect_uri': auth0_callback,
            'code': code,
            'grant_type': 'authorization_code',
        }
        url = f'https://{auth0_domain}/oauth/token'
        headers = {'content-type': 'application/json'}
        
        response = requests.post(
            url,
            headers=headers,
            data=json.dumps(data),
        )
        if response.status_code == 200 :
            tokens = response.json()
            access_token = tokens['access_token']
            id_token = tokens['id_token']
            request.session['acess_token'] = access_token
            request.session['id_token'] = id_token
            
            userinfo_response = requests.get(
                f'https://{auth0_domain}/userinfo',
                headers={
                    'authorization': f'Bearer {access_token}'
                }
            )
            userinfo = userinfo_response.json()
            
            management_api_token = get_management_access_token()
            user_id = userinfo['sub'].replace('auth0|', '')
            user_detail_url = f'https://{auth0_domain}/api/v2/users/{user_id}'
            headers = {
                'content-type': 'application.json',
                'Authorization': f'Bearer {management_api_token}'
            }
            
            user_detail_response = requests.get(user_detail_url, headers=headers)
            user_detail = user_detail_response.json()
            userinfo['user_metadata'] = user_detail.get('user_metadata', {})
            
            request.session['userinfo'] = userinfo
            
            print(userinfo)
            return redirect('user:user')
        else :
            print('ユーザー登録に失敗しました…', response.content)
    else :
        return redirect('user:login')

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 7, 2023, 2:18pm UTC](https://community.auth0.com/t/unable-to-retrieve-username/112638/3 "2023-08-07T14:18:27Z")

</div>

Hi @Koki-1205,

See this topic:

> [@How do I get username from a JWT from a React app?](https://community.auth0.com/t/how-do-i-get-username-from-a-jwt-from-a-react-app/51952):
>
> I have a similar problem to this thread: [Not getting userinfo data with express-jwt](https://community.auth0.com/t/not-getting-userinfo-data-with-express-jwt/24618) I have a react app that uses the @auth0/auth0-react package that needs to call a GraphQL API. Here’s how I’m configuring Apollo Client: const { isLoading, isAuthenticated, getAccessTokenSilently } = useAuth0(); let headers: Record\<string, string\> | undefined = undefined; console.log("Getting access token"); try { const token = await getAccessTokenSilently(); console.log(token); headers = { authorizat…

Let me know if you have any questions!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 21, 2023, 2:18pm UTC](https://community.auth0.com/t/unable-to-retrieve-username/112638/4 "2023-08-21T14:18:53Z")

</div>

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