# How can we request the 'id\_token'. After the authentication done?

**URL:** <https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [April 12, 2021, 8:32am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942 "2021-04-12T08:32:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![haroon.momin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/haroon.momin/32/13039_2.png) [@haroon.momin](https://community.auth0.com/u/haroon.momin)\
**Post date:** [April 12, 2021, 8:32am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/1 "2021-04-12T08:32:32Z")

</div>

Hi there,  
I am using php-laravel 6.2 and auth0, I am able to log in and get the ‘access\_token’ and ‘id\_token’.  
But i want to get the ‘id\_token’ for any api I have to consume in my php-side.  
How can i generate/get the “id\_token” after the user is logged in?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 12, 2021, 2:54pm UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/3 "2021-04-12T14:54:09Z")

</div>

Hi @haroon.momin,

I am not too familiar with Laravel, but I will try to help!

> [@haroon.momin](#):
>
> But i want to get the ‘id\_token’ for any api I have to consume in my php-side.

Just to clarify, are you wanting the Access Token or ID Token for the user? APIs should only be concerned with the Access Token. If you have multiple APIs which the user should have access to, then you can consider the following approach: [Configure Logical API for Multiple APIs](https://auth0.com/docs/authorization/represent-multiple-apis-using-a-single-logical-api)

> [@haroon.momin](#):
>
> How can i generate/get the “id\_token” after the user is logged in?

The [Laravel quickstart](https://auth0.com/docs/quickstart/webapp/laravel/01-login) provides the following example for getting the user’s info once logged in:

```auto
class CustomUserRepository extends Auth0UserRepository
{
    protected function upsertUser( $profile ) {
        return User::firstOrCreate(['sub' => $profile['sub']], [
            'email' => $profile['email'] ?? '',
            'name' => $profile['name'] ?? '',
        ]);
    }

    public function getUserByDecodedJWT(array $decodedJwt) : Authenticatable
    {
        $user = $this->upsertUser( $decodedJwt );
        return new Auth0JWTUser( $user->getAttributes() );
    }

    public function getUserByUserInfo(array $userinfo) : Authenticatable
    {
        $user = $this->upsertUser( $userinfo['profile'] );
        return new Auth0User( $user->getAttributes(), $userinfo['accessToken'] );
    }
}

```

---

<div class="post-metadata">

**Author:** ![haroon.momin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/haroon.momin/32/13039_2.png) [@haroon.momin](https://community.auth0.com/u/haroon.momin)\
**Post date:** [April 14, 2021, 6:15am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/4 "2021-04-14T06:15:16Z")

</div>

Hi @stephanie.chamblee,  
Thanks for your response. I have already done that but no luck.  
Can i ask you one question, In the “access\_token” apart from the ‘sub’ can i use email?  
Right now,  
{  
“iss”: “https://{{domain}}/”,  
“sub”: “auth0|auth0 id”,  
“aud”: [  
“[http://localhost:9090](http://localhost:9090)”,  
“https://{{domain}}/userinfo”  
],  
“iat”: 1618380170,  
“exp”: 1618466570,  
“azp”: “UvNTilRKJndStaMIcG41IeUjRhoJWL4Z”,  
“scope”: “openid profile email”  
}  
I want,  
{  
“iss”: “https://{{domain}}/”,  
“email”: “user email”,  
“aud”: [  
“[http://localhost:9090](http://localhost:9090)”,  
“https://{{domain}}/userinfo”  
],  
“iat”: 1618380170,  
“exp”: 1618466570,  
“azp”: “UvNTilRKJndStaMIcG41IeUjRhoJWL4Z”,  
“scope”: “openid profile email”  
}

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 14, 2021, 11:10am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/5 "2021-04-14T11:10:57Z")

</div>

The Access Token won’t contain any user info except the user ID.

You can use the user ID to request user info by using the `/userinfo` endpoint. You can also add custom claims to the Access Token using rules: [Sample Use Cases: Scopes and Claims](https://auth0.com/docs/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token)

Only the ID Token will contain all of the user profile info.

[https://community.auth0.com/t/what-is-the-difference-between-idtoken-accesstoken/10843](https://community.auth0.com/t/what-is-the-difference-between-idtoken-accesstoken/10843)

---

<div class="post-metadata">

**Author:** ![haroon.momin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/haroon.momin/32/13039_2.png) [@haroon.momin](https://community.auth0.com/u/haroon.momin)\
**Post date:** [April 14, 2021, 11:37am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/6 "2021-04-14T11:37:23Z")

</div>

@stephanie.chamblee,  
endpoint ‘/userinfo’ is having the rate\_limit. Not feasible.  
I wish apart from ‘sub’ if we could use the email. Becoz user\_id is not my PK.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 14, 2021, 1:33pm UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/7 "2021-04-14T13:33:45Z")

</div>

I see, thanks for clarifying! In that case, you can add the user’s email in the Access Token by creating a [rule](https://auth0.com/docs/rules). Go to **Auth pipeline \> Rules** in your Auth0 dashboard. Click **+ CREATE RULE** and select **Empty rule**. Paste in this rule, replacing the namespace with your app’s URI (a namespace is required so that the claim does not collide with others):

```auto
function(user, context, callback) {
  const namespace = 'https://myapp.example.com/';
  context.accessToken[namespace + 'email'] = user.email;
  callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![haroon.momin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/haroon.momin/32/13039_2.png) [@haroon.momin](https://community.auth0.com/u/haroon.momin)\
**Post date:** [April 20, 2021, 10:49am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/8 "2021-04-20T10:49:04Z")

</div>

Hi,  
app’s URI means the auth0 domain OR the what.  
Currently, i am on the localhost. So, how can i use this to accomplish this?  
If my App name is ‘MynewApp’ then how the URI will be?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 20, 2021, 11:45am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/9 "2021-04-20T11:45:04Z")

</div>

A namespace is required for custom claims so that your claims will not collide with the reserved claims or claims from other resources. If you try to add a custom claim that is not namespace, it will be silently filtered out and won’t be present in the Access Token.

The namespace has to use the format `https://some-domain,` but if you don’t have a domain for your app yet, this can be anything (e.g. `https://MynewApp.com`). Once you have a domain for your app, you can use that as the namespace.

Here is more info about creating a namespace for custom claims:

[https://auth0.com/docs/tokens/create-namespaced-custom-claims](https://auth0.com/docs/tokens/create-namespaced-custom-claims)

---

<div class="post-metadata">

**Author:** ![haroon.momin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/haroon.momin/32/13039_2.png) [@haroon.momin](https://community.auth0.com/u/haroon.momin)\
**Post date:** [April 25, 2021, 10:06am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/10 "2021-04-25T10:06:13Z")

</div>

@stephanie.chamblee, Thank you very much it works.

---

<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:** [May 10, 2021, 10:07am UTC](https://community.auth0.com/t/how-can-we-request-the-id-token-after-the-authentication-done/60942/11 "2021-05-10T10:07:04Z")

</div>

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