Socialite Google redirect_uri_mismatch
Asked Answered
B

3

5

I am trying to login with google using socialite , my facebook login works fine so the problem in my google app, any help!!!

 'google' => [
    'client_id' =>      'app-key',
    'client_secret' =>  'app-secret',
    'redirect' =>       'http://www.shoptizer.com/callback/google',
],

google login Credentials

Balliett answered 20/11, 2018 at 18:10 Comment(1)
all your authorized redirect url's registered with https in google. Do you have any https redirection? Because, in your config there is http based callback url.Newish
C
2

I found this link https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-google-login.html

From this tutorial:

Occasionally it happens that google require some time to apply client configuration If you get an error message redirect_uri_missmatch wait couple of minutes and it should work normally.

Also change the redirect uri by:

'google' => [
   'client_id' =>      'app-key',
   'client_secret' =>  'app-secret',
   'redirect' =>       'https://www.shoptizer.com/callback/google',
],

If your app is provided by https you must match your http scheme on google api and on your redirect callback.

Charlettecharley answered 20/11, 2018 at 18:19 Comment(2)
I am waiting more than 2 hours nowBalliett
thanks that was the mistake I had to change it to httpsBalliett
E
6

Also one more point to remember that Socialite also gives uri_mismatch_error even when your redirects are correctly defined in google console but you dynamically changed the redirectUrl through

return Socialite::with('google')->redirectUrl($redirect_url)->redirect();

So plz take care that you should also need to define while receiving the response

Socialite::driver('google')->redirectUrl($redirect_url)->stateless()->user();

where $redirect_url is your custom redirect url. After google redirects you to correct place, but even then Socialite checks it at its end.

Echopraxia answered 28/12, 2018 at 0:10 Comment(1)
Very good point! This was what I needed. Also note that you should use the ->redirectUrl() method, and not the ->with(['redirect_uri' => '...']) one, as the second one still causes the same error.Rye
C
2

I found this link https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-google-login.html

From this tutorial:

Occasionally it happens that google require some time to apply client configuration If you get an error message redirect_uri_missmatch wait couple of minutes and it should work normally.

Also change the redirect uri by:

'google' => [
   'client_id' =>      'app-key',
   'client_secret' =>  'app-secret',
   'redirect' =>       'https://www.shoptizer.com/callback/google',
],

If your app is provided by https you must match your http scheme on google api and on your redirect callback.

Charlettecharley answered 20/11, 2018 at 18:19 Comment(2)
I am waiting more than 2 hours nowBalliett
thanks that was the mistake I had to change it to httpsBalliett
M
0

The problem is in the default url, you must change it on two occasions: before the redirect and before getting the user data.

Do not do this:

return Socialite::driver('google')->redirectUrl($yourredirecturl)->redirect();

Do it:

config()->set('services.google.redirect', $yourredirecturl);
return Socialite::driver('google')->redirect();

And when accessing user data, do this:

config()->set('services.google.redirect', $yourredirecturl);
$user = Socialite::driver('google')->user();
Manners answered 15/1, 2022 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.