Laravel Socialite: Legacy People API has not been used in project
Asked Answered
T

4

6

I have used Laravel 5.4 with socialite 3.0 for social login on my web application. But nowadays I got an error Legacy People API has not been used in project xxx. Then I have made some changes in a core file of socialite package. /vendor/laravel/socialite/src/Two/GoogleProvider.php Line 61: Replace https://www.googleapis.com/plus/v1/people/me? by https://www.googleapis.com/oauth2/v3/userinfo?

And update mapUserToObject function with below code:

protected function mapUserToObject(array $user)
{
    $user['id'] = Arr::get($user, 'sub');
    $user['verified_email'] = Arr::get($user, 'email_verified');
    $user['link'] = Arr::get($user, 'profile');

    return (new User)->setRaw($user)->map([
        'id' => Arr::get($user, 'sub'),
        'nickname' => Arr::get($user, 'nickname'),
        'name' => Arr::get($user, 'name'),
        'email' => Arr::get($user, 'email'),
        'avatar' => $avatarUrl = Arr::get($user, 'picture'),
        'avatar_original' => $avatarUrl,
    ]);
}
Tetreault answered 5/11, 2019 at 7:27 Comment(6)
Alright? Are you facing any issue or getting any error?Swage
Yes, I was faced but resolved now.Tetreault
Hey! I face the same error (Legacy People API has not been used in project) from the beginning of the week... Everything worked properly for few months. Have you found any solution to the issue? For now, I had to create a new project to fix that :|Oaxaca
@Oaxaca Just follow the above steps and the issue gets fixed in your existing project also. Please drop a message here if still not fixed.Tetreault
@VineetChauhan , can you please let me know which steps to follow for fixing this issue ?Bohol
Update socialite package to 3.3.0Wendling
D
7

This Solution does work. Fixed my issue.

Thanks a lot.

Here is the whole file if anybody is having this issue. Just change GoogleProvider class located in: ./vendor/laravel/socialite/src/Two/GoogleProvider.php with this:

class GoogleProvider extends AbstractProvider implements ProviderInterface{

protected $scopeSeparator = ' ';

/**
 * The scopes being requested.
 *
 * @var array
 */
protected $scopes = [
    'openid',
    'profile',
    'email',
];

/**
 * {@inheritdoc}
 */
protected function getAuthUrl($state)
{
    return $this->buildAuthUrlFromBase('https://accounts.google.com/o/oauth2/auth', $state);
}

/**
 * {@inheritdoc}
 */
protected function getTokenUrl()
{
    return 'https://accounts.google.com/o/oauth2/token';
}

/**
 * Get the POST fields for the token request.
 *
 * @param  string  $code
 * @return array
 */
protected function getTokenFields($code)
{
    return array_add(
        parent::getTokenFields($code), 'grant_type', 'authorization_code'
    );
}

/**
 * {@inheritdoc}
 */
protected function getUserByToken($token)
{
    //fixing legacy google+ api
    $response = $this->getHttpClient()->get('https://www.googleapis.com/oauth2/v3/userinfo?', [
        'query' => [
            'prettyPrint' => 'false',
        ],
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.$token,
        ],
    ]);
    return json_decode($response->getBody(), true);
}

/**
 * {@inheritdoc}
 */
protected function mapUserToObject(array $user)
{
    //fixing legacy google+ api
    $user['id'] = Arr::get($user, 'sub');
    $user['verified_email'] = Arr::get($user, 'email_verified');
    $user['link'] = Arr::get($user, 'profile');

    $avatarUrl = Arr::get($user, 'image.url');
    return (new User)->setRaw($user)->map([
        'id' => Arr::get($user, 'sub'),
        'nickname' => Arr::get($user, 'nickname'),
        'name' => Arr::get($user, 'name'),
        'email' => Arr::get($user, 'email'),
        'avatar' => $avatarUrl = Arr::get($user, 'picture'),
        'avatar_original' => $avatarUrl,
    ]);

}

}

Dubai answered 5/11, 2019 at 21:6 Comment(4)
thanks bro, it works for me.. googleapis.com/plus/v1/people/me? url with googleapis.com/oauth2/v3/userinfo?Appendicular
Update socialite package to 3.3.0Wendling
Been trying to figure this out and came across this and now all is well. On production side there wasn't a problem, but seems google only allows the legacy api endpoint if your app hit that legacy endpoint within 6 months. Since I took a break from developing my site, upon returning I had this problem with legacy!Integration
@Integration If you already had the depreciated API working google will allow the API call but if your app hasn't been calling the API in the past they will want you to use the new callDubai
A
3

Replace

https://www.googleapis.com/plus/v1/people/me? url with https://www.googleapis.com/oauth2/v3/userinfo?

Google has update the API Endpoint & it recommend to use this https://www.googleapis.com/oauth2/v3/userinfo? endpoint to get the user details.

https://developers.google.com/people/legacy

Appendicular answered 8/1, 2020 at 17:57 Comment(2)
Update socialite package to 3.3.0Wendling
@EmptyBrain It's a production server. I don't want to change anything to avoid any complications. For now, this is working fine for me.Dubai
K
1

I also have Laravel 5.4 and in my case helped upgrade laravel/socialite from 3.0.* to 3.4.

I set this setting in composer: "laravel/socialite": "~3.0" and ran composer update. Don't forget to clear cache: php artisan cache:clear

Kristy answered 5/1, 2021 at 14:35 Comment(0)
I
0

The trick here is that it says legacy people api, this often means you are trying to use one of the old Google+ scopes.

A lot of the profile related endpoints that where once part of the google+ api were moved to the People api after the shutdown of Google+ .

As you can see by the endpoint you are calling you are trying to use the old google+ endpoint which was shutdown years ago.

googleapis.com/plus/v1

You should be using people.get

The correct endpoint would be.

GET https://people.googleapis.com/v1/{resourceName=people/*}
Infringement answered 30/8, 2021 at 11:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.