Laravel社交名流配置访问类型为离线在谷歌登录


Laravel socialite config access type as offline in google login

好吧,我试图在laravel 5.1实现与谷歌使用socialite登录,我没有问题的范围,但我需要实现access_type作为离线,有人知道,我怎么能在socialite配置这个laravel?

这是我的连接线

$scopes = [
        'https://www.googleapis.com/auth/plus.me',
        'https://www.googleapis.com/auth/plus.profile.emails.read',
        'https://www.googleapis.com/auth/gmail.readonly'
    ];
    return Socialize::driver('google')->scopes($scopes)->setAccessType('offline')->redirect();

谢谢你的帮助

自上次回答此问题以来可能更新;看起来泰勒添加了传递可选参数的功能。使用关联数组调用with方法:

$scopes = [
    'https://www.googleapis.com/auth/plus.me',
    'https://www.googleapis.com/auth/plus.profile.emails.read',
    'https://www.googleapis.com/auth/gmail.readonly'
];
$parameters = ['access_type' => 'offline'];
return Socialite::driver('google')->scopes($scopes)->with($parameters)->redirect();

真的昨天在玩Gmail API时遇到了这个问题。

我假设您想要为已经经过身份验证的用户获取刷新令牌。我无法在Socialite中找到原生的方法(我不确定你从哪里获得setAccessType()方法,因为它不存在于Google或抽象提供者类中)。

最后,我只是暂时改变了getAuthUrl()方法返回的字符串,以在结束时附加查询字符串参数,经过身份验证过程,然后恢复文件(以免下次我更新时让Composer呻吟)。

这不是一个理想的解决方案,但如果您只是想重新验证自己,希望它能有所帮助。