php – 使用Laravel Socialite获取Google刷新令牌

前端之家收集整理的这篇文章主要介绍了php – 使用Laravel Socialite获取Google刷新令牌前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用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();

猜你在找的Laravel相关文章