Closed lbreza closed 3 years ago
However it works normally if you test it locally (localhost).
This just leads me to believe there's something wrong with your setup in production.
Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to report back and I'll gladly help you out and re-open this issue.
Thanks!
However it works normally if you test it locally (localhost).
This just leads me to believe there's something wrong with your setup in production.
Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to report back and I'll gladly help you out and re-open this issue.
* [Laracasts Forums](https://laracasts.com/discuss) * [Laravel.io Forums](https://laravel.io/forum) * [StackOverflow](https://stackoverflow.com/questions/tagged/laravel) * [Discord](https://discordapp.com/invite/KxwQuKb) * [Larachat](https://larachat.co) * [IRC](https://webchat.freenode.net/?nick=laravelnewbie&channels=%23laravel&prompt=1)
Thanks!
You were right.
After additional debugging and researching I figured out that it was problem with server ModSecurity.\ It was blocking the Google callback request...
Thank you!
@lbreza Could you solve it in the end? I have the same error
@lbreza Could you solve it in the end? I have the same error
Yes. In my case it was ModSecurity (web based firewall) on production server which was blocking the requests for Google API.
Disabling some of the ModSecurity rules worked in the end.
In my case, the error occurred when user declined to accept google agreement and google redirected user to the callback url with error query parameter and I forgot to check error and continued to get user using socialite package.
Example response by callback: https://example.com?error=access_denied&state=blahblah
yes sir thanks for your answer @emf-developer . Before i know that, my code like this.
$user = Socialite::driver($provider)->stateless()->user();
$existingUser = User::where('email', $user->email)->first();
on my history error happen in method user() after stateless() like your answer, the problem happen when user cancel sign in to process
so we apply try catch like this
try { $user = Socialite::driver($provider)->stateless()->user(); } catch (\Exception $e) { return redirect()->to('https://blablabla.id/login'); }
and it solved. So, thank you sir
Description:
I know there were already some of the issues (#294) related to this but this still haven't been fixed and it's bothering me for some time because I can't make it work.
It may be problem only for the specific cases but in some cases it's not working.\ If I'm wrong please correct me.
Problem is with Google provider because it returns the exception when you want to handle the callback and retrieve user details.
Socialite::driver('google')->stateless()->user()
returns
GuzzleHttp\Exception\ClientException Client error: POST https://www.googleapis.com/oauth2/v4/token resulted in a 400 Bad Request response: { "error": "invalid_request", "error_description": "Missing required parameter: code" }
However it works normally if you test it locally (localhost).
You can make it work on live server (production) only when you remove
'profile'
from$scopes
atsocialite/src/Two/GoogleProvider.php
but you don't receive user details such asgiven_name
,family_name
, ... which are needed.Steps To Reproduce:
socialite/src/Two/GoogleProvider.php
file setSocialite::driver('google')->stateless()->user()
works and you get all the user information when you handle the callback.