0

I implemented social login with laravel socialite for facebook and google, and while it works for facebook for google it gives me this error

Client error: GET https://www.googleapis.com/userinfo/v2/me?prettyPrint=false resulted in a 401 Unauthorized response: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 (truncated...)

This is my login method:

   public function socialLogin($provider, $accessToken)
  {


        $providerUser = Socialite::driver($provider)->userFromToken($accessToken);

        $user = Reader::whereEmail($providerUser->getEmail())->first();

        if (!$user) {

            $user = Reader::create([
                'email' => $providerUser->getEmail(),
                'name' => $providerUser->getName(),
            ]);
        }

        if ($user) {
            $user->comment_count = DB::table(DB::raw('comments'))->where('author_id', $user->id)         
            ->count();

            return $user;

        }
        return $user;
    }

I get the access token but when it comes to this line

$providerUser = Socialite::driver($provider)->userFromToken($accessToken);

it shows the error from above. I have to mention that I'm working on an older laravel project that uses laravel 5.2 Can someone help?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Emia
  • 55
  • 8
  • userFromToken($accessToken) <-- i dont think that method takes an access token. – Linda Lawton - DaImTo Mar 04 '20 at 13:48
  • @DalmTo but it does: "If you already have a valid access token for a user, you can retrieve their details using theuserFromToken method:" ```$user = Socialite::driver('google')->userFromToken($token);``` – Emia Mar 04 '20 at 14:07
  • Request is missing required authentication credential <-- but its not its telling you that the authentication is missing. – Linda Lawton - DaImTo Mar 04 '20 at 14:08

0 Answers0