使用JS SDK将access_token传递到FB.login()

问题描述 投票:0回答:1

因此,请快速浏览一下我正在研究的内容。我已经使用Google和Facebook开发了一个OAuth库,以将其集成到我们的公司软件中。我们的协议栈包含了最新版本的Lucee(Coldfusion),因此很多身份验证是按照其文档手动进行的。尽管我确实使用了每个SDK,但我只需要担心对返回的令牌服务器端进行身份验证。

但是对于Facebook,当用户已经在其他地方登录FB时,在页面加载时初始化SDK时,他们已经处于authorize状态。每当我选择“继续使用Facebook”,编辑权限并拒绝电子邮件权限时,我都会返回给用户,说明我们为什么需要他们的电子邮件,并提供一个按钮来重新启动登录流程,重新请求电子邮件权限,或者只是一起停止。

尽管我选择添加电子邮件权限,但是使用auth_type: 'rerequest'时出现以下错误。

You are overriding current access token, that means some other app is expecting different access token and you will probably break things. Please consider passing access_token directly to API parameters instead of overriding the global settings.

我了解错误的含义以及原因,但是我不知道如何解决该问题?从我发现的所有研究中,到处都有状态将访问令牌传递给API,但是所有示例都使用使用href而不是SDK登录功能的URL端点来实现。这可以通过他们的SDK来完成吗?

这是我的FB.login()函数的外观:

if( FB.getAccessToken() ) {

    var authType = 'rerequest';

} else {

    var authType = 'reauthorize';
}

FB.login(function(response) {

    // Check to see if user logged in to grant us permission
    if(response.authResponse && response.authResponse.grantedScopes) {

        let isConnected = response.status === 'connected';
        let grantedScopes = response.authResponse.grantedScopes.search('email') !== -1;

        // Need user permission to access email
        if(isConnected && grantedScopes) {

            FacebookAuth.updateSigninStatus();

        } else {

            // Re-ask for email permission
            alertUserError(false, 'Facebook');
        }
    }
}, {
    auth_type: authType,
    scope: 'email',
    return_scopes: true,
    access_token: FB.getAccessToken() // Trying to pass current access_token here, but FB.login() generates new token
});
javascript facebook facebook-javascript-sdk
1个回答
0
投票

再看一下Facebook文档,并决定在创建访问令牌以验证用户服务器端时走存储令牌的路线。而不是使用Facebook SDK来执行此操作,该操作不会重复登录过程,创建新的访问令牌并生成该错误。

https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#token

© www.soinside.com 2019 - 2024. All rights reserved.