socialite: Failed login with google
I got this issue ones i upload to the server:
Client error: POST https://accounts.google.com/o/oauth2/token resulted in a 400 Bad Request response: { “error”: “invalid_request”, “error_description”: “Missing required parameter: code” }
any solution, thx in advance.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (2 by maintainers)
same problem here i’m just facing it. the funny thing is i recently found a solution from stackoverflow that from
the solution is to remove the profile from scopes in vendor\laravel\socialite\src\Two\GoogleProvider.php
protected $scopes = [ ‘openid’, ‘email’, ];
but when i removed the ‘profile’ scope it works fine for login only [ like who ever sign in/sign up previously for them that works fine ] But for new user they can’t login/sign up … if anyone can find some solution kindly suggest . [thanks in advance]
I think this is bug, I tried all the options but it’s not working. Please test it with latest version of Google API.
It works just fine for Facebook. But for Google, the code is missing.
Can you share how you fixed the issue?
@Hujjat @Nirjhor3029 solution does not give name of user thats not a solution.
why has the case been closed? what is the solution?
I have the same case, the problem occurs when on the server.
on localhost the normal way.
I found a fix for this. Google sent back a payload after requesting OAUTH. The payload contains a code object that you are supposed to send as headers along with the callback route on Socialite.
Socialite is not sending the code response back to google thus the error. Fixed it without having to remove profile from the scopes
vendor\laravel\socialite\src\Two\GoogleProvider.phpObject { code: "4/vAEVuHyCL3tmV8lv6jbJvsxllVOz4tq-iNxY5AC2fMJqTZMgu8u_B5S98mQCjPu1mGjskL9AA836zoT2sp8huNQ", scope: "email+profile+openid+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email", authuser: "1", session_state: "ae674d53c3d40e64a9a8aa79089b955a4e552bfc..cd9f", prompt: "consent" }When I removed profile I don’t see error but the name and nickname parameter becomes null.