【问题标题】:Getting Google Refresh Token with Laravel Socialite使用 Laravel Socialite 获取 Google Refresh Token
【发布时间】:2016-08-30 00:48:11
【问题描述】:

使用 Laravel Socailite 连接到 Google API 并且我恢复连接正常,但是此访问不会返回刷新令牌,因此我的连接超时。

$scopes = [
            'https://www.googleapis.com/auth/webmasters',
            'https://www.googleapis.com/auth/webmasters.readonly',
            'https://www.googleapis.com/auth/analytics.readonly',
            'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email',
          ];    
$parameters = ['access_type' => 'offline'];
return Socialite::driver('google')->scopes($scopes)->with($parameters)->redirect();

如何取回刷新令牌?

【问题讨论】:

  • 我遇到了同样的问题。运气好了吗?

标签: php laravel google-api google-api-php-client laravel-socialite


【解决方案1】:

当您将用户重定向到 Google 时,在重定向时使用 with() 方法将 access_type 设置为离线,如下所示:

return Socialite::driver('google')
    ->scopes() // For any extra scopes you need, see https://developers.google.com/identity/protocols/googlescopes for a full list; alternatively use constants shipped with Google's PHP Client Library
    ->with(["access_type" => "offline", "prompt" => "consent select_account"])
    ->redirect();

【讨论】:

  • 默认refresh_token只在第一次授权时返回,通过添加"prompt" => "consent select_account"我们强制每次都返回。
  • 刷新令牌不会过期,所以您只需要第一次使用它吗?
猜你喜欢
  • 2022-01-04
  • 1970-01-01
  • 2015-05-19
  • 2018-09-11
  • 2019-09-17
  • 1970-01-01
  • 1970-01-01
  • 2020-05-26
  • 2019-06-16
相关资源
最近更新 更多