【问题标题】:Socialite Google redirect_uri_mismatch社交名媛 Google redirect_uri_mismatch
【发布时间】:2019-04-23 06:03:35
【问题描述】:

我正在尝试使用社交名流登录谷歌,我的 Facebook 登录工作正常,所以我的谷歌应用程序中的问题,任何帮助!!!

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

【问题讨论】:

  • 您所有授权的重定向 url 都在 google 中使用 https 注册。你有任何https重定向吗?因为,在您的配置中有基于 http 的回调 url。

标签: laravel google-plus laravel-socialite


【解决方案1】:

还有一点要记住,即使您在 Google 控制台中正确定义了重定向但您通过动态更改了 redirectUrl,Socialite 也会提供 uri_mismatch_error

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

所以请注意,您在接收响应时还需要定义

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

其中 $redirect_url 是您的自定义重定向网址。 在 google 将您重定向到正确的位置之后,但即使如此,Socialite 也会在其末尾检查它。

【讨论】:

  • 非常好!这正是我所需要的。另请注意,您应该使用->redirectUrl() 方法,而不是->with(['redirect_uri' => '...']) 方法,因为第二种方法仍然会导致相同的错误。
【解决方案2】:

我找到了这个链接https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-google-login.html

来自本教程:

有时 google 需要一些时间来应用客户端配置如果您收到错误消息 redirect_uri_missmatch 等待几分钟,它应该可以正常工作。

还可以通过以下方式更改重定向 uri:

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

如果您的应用由 https 提供,您必须在 google api 和重定向回调上匹配您的 http 方案。

【讨论】:

  • 我现在等了两个多小时
  • 谢谢这是我不得不将其更改为 https 的错误
【解决方案3】:

问题出在默认 url,你必须在两种情况下更改它:重定向之前和获取用户数据之前。

不要这样做:

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

这样做:

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

当访问用户数据时,这样做:

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

【讨论】:

    猜你喜欢
    • 2018-12-20
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 2023-03-08
    • 2017-03-04
    • 2021-11-18
    • 1970-01-01
    相关资源
    最近更新 更多