簡體   English   中英

使用Laravel Socialite獲取Google刷新令牌

[英]Getting Google Refresh Token with Laravel Socialite

使用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();

如何獲取刷新令牌?

當您將用戶重定向到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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM