从 Google OAuth 连接用户后,当该用户希望在需要选择其 Google 帐户的下一个会话期间重新连接时,将再次请求许可。
根据文档 https://developers.google.com/identity/protocols/OpenIDConnect#prompt,参数的行为prompt负责授权请求的如下:
如果未指定值且用户之前未授权
访问,然后向用户显示同意屏幕。
因此,用户不必重新订购他的同意(经过验证,该应用程序存在于我的授权中)。
设想的唯一答案是这个问题的答案:使用谷歌登录总是征求用户同意 https://stackoverflow.com/questions/14923799/login-with-google-always-asks-user-consent
因为我也在没有安全 HTTP 的情况下在本地工作,但他假设存在 cookie 策略,但事实并非如此。
代码生成URL
/**
* Create a new OAuth2Client with the credentials previously loads
*/
private getOAuth2() : OAuth2Client {
return new OAuth2(
this.credentials.client_secret,
this.credentials.client_id,
this.credentials.redirect_uris[0]
);
}
/**
* Create connection URL for the given scopes
* @param scopes
*/
public url(scopes: Array<string>) : string {
return this.client.generateAuthUrl({
access_type: "offline",
scope: scopes
});
}
// The scope used to generate URL is 'https://www.googleapis.com/auth/youtube.readonly'
// this.client refer to a client which is load by getOAuth2
// and use only for the generation of URL's.
当用户第二次登录时,要获取已丢失的刷新令牌,不需要再次给予同意:
这就是出现的问题。
TBH,我没有清楚地理解你的问题。但是,我确信您必须处理两个不同的令牌。由于它是 OAuth,因此在成功进行用户身份验证后,首先您将获得来自 Google 的访问令牌。
您应该使用该访问令牌从 Google 获取用户信息。但默认情况下,访问令牌有一定的过期时间,超过该时间用户必须重新授权您的应用程序。我怀疑这就是你的情况。
您可以通过使用刷新令牌来更新您的访问令牌,在获得用户同意后您将获得该令牌。
您可以在我写的这篇博文中获得详细信息,https://www.syncwithtech.org/authorizing-google-apis/ https://www.syncwithtech.org/authorizing-google-apis/
我希望这可以在某种程度上帮助您。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)