尽管提示没有价值,谷歌认证总是要求授权

Neo*_*eok 5 oauth google-api node.js google-oauth

从Google OAuth连接用户后,如果此用户希望在下一个需要选择其Google帐户的会话期间重新连接,则会再次询问该权限.

根据文档,负责授权请求的参数提示的行为如下:

如果未指定任何值且用户先前未授权访问,则会向用户显示同意屏幕.

因此,用户不必重新排序他的同意(通过验证,该申请存在于我的授权中).

设想的唯一答案是关于这个问题的答案:用谷歌登录总是要求用户同意

因为我也在没有安全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.
Run Code Online (Sandbox Code Playgroud)

当用户第二次登录时,为了获得丢失的刷新令牌,他或她不需要再次同意:

在此输入图像描述

这就是发生的问题.

vic*_*ke4 2

TBH,我没有清楚地理解你的问题。但是,我确信您必须处理两个不同的令牌。由于它是 OAuth,因此在成功进行用户身份验证后,首先您将获得来自 Google 的访问令牌。

您应该使用该访问令牌从 Google 获取用户信息。但默认情况下,访问令牌有一定的过期时间,超过该时间用户必须重新授权您的应用程序。我怀疑这就是你的情况。

您可以通过使用刷新令牌来更新您的访问令牌,在获得用户同意后您将获得该令牌。

您可以在我写的这篇博文中获取详细信息,https://www.syncwithtech.org/authorizing-google-apis/

我希望这可以在某种程度上帮助您。