How to access user email in upsertUser($profile) function with Laravel?

I am following the quickstart guide for PHP Laravel and have made my own custom UserRepository class. When I try to do login with linkedin though, in the $profile variable I don’t have access to name or email, there is only the sub value. This is the code in the quickstart:

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

My code:

    protected function upsertUser( $profile ) {
        dd($profile);
        return User::firstOrCreate(['sub' => $profile['sub']]);
    }

When I die and dump the $profile variable I only have access to the sub key. I am wondering, how can I return back the email value on the $profile object?

dd result:
Screen Shot 2020-04-04 at 10.10.00 AM

On the auth0 dashboard under Connections -> Social -> LinkedIn I have the email address box checked. My question is how can I access the users email on the $profile object in the upsertUser function?

Screen Shot 2020-04-04 at 10.12.06 AM

In the LinkedIn developer console I have the email permission enabled:

Ahhh woops. This issue can be resolved. For my login method I was only using the “openid” scope. Instead I needed to expand my scopes to include profile and email :slight_smile:

    /**
     * Go to the Auth0 login page
     *
     * @return mixed
     */
    public function loginPage()
    {
        $authorize_params = [
            'scope' => 'openid profile email',
        ];
        return \App::make('auth0')->login(null, null, $authorize_params);
    }
1 Like

Glad you have figured it out @connor11528!