Skip to main content

Issue - Laravel Socialite: Legacy People API has not been used in project

If you have an issue with Google Login in Laravel Socialite, Follow these instructions.

Change this file ./vendor/laravel/socialite/src/Two/GoogleProvider.php with this:

<?php
namespace Laravel\Socialite\Two;

use Illuminate\Support\Arr;

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,
        ]);

    }
}

Comments

Popular posts from this blog

get records using location by dynamic radius from database.

$postads = PostAds::with('userInfo')                             ->has('userInfo')                             ->where('user_id','!=',Auth::id())                             ->whereRaw('(ST_Distance_Sphere(POINT('.$lng.','.$lat.'), POINT(longitude,latitude))/1000) <= radius')                             ->paginate(10);

Get Text difference between new and old

Sample output: THis are my car. This is  my car. function htmlDiff($old, $new){         $diff = self::diffArray(explode(' ', $old), explode(' ', $new));         $flag = 0;         $ret = "";         foreach($diff as $i => $k){             if(is_array($k)){                 if((count($k['d']) != 0) && (count($k['i']) == 0)){                     $flag = 1;                 }                 else if((count($k['d']) != 0) && (count($k['i']) != 0)){                     $ret .= (!empty($k['i'])?"<span style='background-color:#ccffcc'>".implode(' ',$k['i'])."</span> ":'');               ...