Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoogleProvider Type Error #687

Closed
alibori opened this issue Feb 9, 2024 · 3 comments · Fixed by #689
Closed

GoogleProvider Type Error #687

alibori opened this issue Feb 9, 2024 · 3 comments · Fixed by #689

Comments

@alibori
Copy link
Contributor

alibori commented Feb 9, 2024

Socialite Version

5.11

Laravel Version

9.19

PHP Version

8.1

Database Driver & Version

No response

Description

Hi!

I'm using Socialite for a Flutter mobile app with a Laravel Based backend to sign in with a Google Account.

From frontend I pass to backend the Google access token and the error appears when I try to run userFromToken method of the GoogleProvider class.

In concrete it fails when tries to do json_decode from the response because it's receiving a GuzzleHttp\Psr7\Stream instead of a string:

protected function getUserByToken($token)
  {
      $response = $this->getHttpClient()->get('https://www.googleapis.com/oauth2/v3/userinfo', [
          RequestOptions::QUERY => [
              'prettyPrint' => 'false',
          ],
          RequestOptions::HEADERS => [
              'Accept' => 'application/json',
              'Authorization' => 'Bearer '.$token,
          ],
      ]);

      return json_decode($response->getBody(), true);
  }

If instead, I do this the problem is solved:

protected function getUserByToken($token)
  {
      $response = $this->getHttpClient()->get('https://www.googleapis.com/oauth2/v3/userinfo', [
          RequestOptions::QUERY => [
              'prettyPrint' => 'false',
          ],
          RequestOptions::HEADERS => [
              'Accept' => 'application/json',
              'Authorization' => 'Bearer '.$token,
          ],
      ]);

      return json_decode($response->getBody()->getContents(), true);
  }

Any idea about the cause of this?

Thanks a lot!

Steps To Reproduce

  • Create a Laravel 9 project
  • Create a controller to receive a valid Google access token
  • Try to get the user from this token
@driesvints
Copy link
Member

Strange. Could you send in a PR to check for the type from getBody, then use getContents if it's a PSR7 stream? Thanks!

Copy link

github-actions bot commented Feb 9, 2024

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@alibori
Copy link
Contributor Author

alibori commented Feb 9, 2024

Yes, of course I can!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants