Auth0 Home Blog Docs

Easiest way to grab user_metadata with Laravel SDK

The Laravel SDK was very easy to follow and integrate within my application. Kudos to the team!
I noticed in my Auth0 dashboard under “Users” I have the ability to populate “user_metadata” in a JSON format. That’s sweet and I added some values there for myself. However, when I login to my application and use

dd( Auth0::getUser() );

I get

array:2 [▼
    "profile" => array:7 [▼
        "sub" => "auth0|5e******"
        "nickname" => "markus"
        "name" => "m*****"
        "picture" => "https://******s%3A%2*a.png"
        "updated_at" => "2020-02-02T13:04:46.759Z"
        "email" => "m******g"
        "email_verified" => false
    ]
    "accessToken" => null
]

I practically followed the installation instructions in the most vanilla way possible.

I noticed user_metadata does not get included and the accessToken is also null.
Can anyone point me in the direction to get user_metadata in the simplest way with the SDK so that something like the below could work.

dd( Auth0::getUser()->userInfo() )

For those wondering, my scope does include user_metadata

public function login()
    {
        $authorize_params = [
            'scope' => 'openid profile app_metadata user_metadata',
            'redirectUrl' => '/home',
            //'audience' => config('laravel-auth0.api_identifier'),
        ];
        return \App::make('auth0')->login(null, null, $authorize_params);
    }
1 Like

Hi @mproctor,

Welcome to the Auth0 Community forums!

You’re on the right path, but user_metadata and app_metadata are not legitimate scopes. What you want are custom claims. The gist:

Create a rule that adds custom claims to you ID token and / or access token for the user profile attributes you want.

Have a look at this thread:

3 Likes

I have figured it out with this other post I just needed to create the rule in my dashboard and now I see user_metadata entries.

2 Likes

Perfect! Glad you have it working and thanks for sharing with the rest of community!