# Getting user info from JWT on laravel API backend

**URL:** <https://community.auth0.com/t/getting-user-info-from-jwt-on-laravel-api-backend/86708>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [July 10, 2022, 5:09pm UTC](https://community.auth0.com/t/getting-user-info-from-jwt-on-laravel-api-backend/86708 "2022-07-10T17:09:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leandro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leandro/32/38672_2.png) [@leandro](https://community.auth0.com/u/leandro)\
**Post date:** [July 10, 2022, 5:09pm UTC](https://community.auth0.com/t/getting-user-info-from-jwt-on-laravel-api-backend/86708/1 "2022-07-10T17:09:47Z")

</div>

Hi guys , im building my spa + laravel backend platform.  
This is what I have so far:  
1  
Can login with my vuejs spa and get a jwt token form auth0.  
2  
Request a protected route and test both cases:  
a - Valid success message when submiting provided token.  
b - Not authorized message (403) when submiting random Bearer String.  
3 But…  
When decoding jwt there is no usefull info.  
Would you point some working example for this flow?  
How can I get authenticated user info ?

Next I will share my unsuscesfull attempt.  
Taking [this](https://auth0.com/docs/quickstart/backend/php/) and adding some modifications , this is the route I have:

```php
      Route::get('/getAuth0User', function (Request $request) {
      
        $jwt = $_GET['token'] ?? $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['Authorization'] ?? null;

        if ($jwt !== null) {
            // Trim whitespace from token string.
            $jwt = trim($jwt);
        
            if (substr($jwt, 0, 7) === 'Bearer ') {
                $jwt = substr($jwt, 7);
            }
        
            $token = $jwt;
            $tokenParts = explode(".", $token);  
            $tokenHeader = base64_decode($tokenParts[0]);
            $tokenPayload = base64_decode($tokenParts[1]);
            dd($tokenPayload);

    })->middleware(['auth0.authorize']);

```

dd provides something like:

```json
{
  "iss": "https://dev-ezn7tyz.us.auth0.com/",
  "sub": "google-oauth2|11028787487949742512",
  "aud": [
    "https://dev.w.lalal.cial",
    "https://dev-ez67tz.us.auth0.com/userinfo"
  ],
  "iat": 1657477224,
  "exp": 1657563624,
  "azp": "6qqkwbmK1OKqwrSE9Y6JBiiHCXEsIaJd",
  "scope": "openid profile email"
}

```

This does not any make sense for me,  
How can I get usefull data ?

Any feedback would be great!  
Regards.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 11, 2022, 11:41pm UTC](https://community.auth0.com/t/getting-user-info-from-jwt-on-laravel-api-backend/86708/3 "2022-07-11T23:41:28Z")

</div>

Hello @leandro!

> [@leandro](#):
>
> How can I get authenticated user info ?

Good question! The data shown is just the contents of the access token - The following post may be useful in terms of outlining some of the available options:

> [@How to get user information from the Laravel API side](https://community.auth0.com/t/how-to-get-user-information-from-the-laravel-api-side/47021/3):
>
> Hi @thaMink, You have a couple of options to get a user’s information on your API side. Make a request to the Authentication API’s [userinfo endpoint](https://auth0.com/docs/api/authentication#user-profile) to get the user’s profile. Use the Management API’s [get user by id endpoint](https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id) (You might hit the management API rate limit if you are doing this a lot.) Add user data to the access token in a rule with a [custom claim](https://auth0.com/docs/scopes/current/sample-use-cases#add-custom-claims-to-a-token). This one will save you the extra request, but will increase token size. There are tradeoffs for each approach. With the first two y…

Hope this helps!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 26, 2022, 11:41pm UTC](https://community.auth0.com/t/getting-user-info-from-jwt-on-laravel-api-backend/86708/4 "2022-07-26T23:41:57Z")

</div>

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