所以只是快速浏览一下我正在做的事情。我使用 Google 和 Facebook 开发了一个 OAuth 库以集成到我们公司的软件中。我们的堆栈由最新版本的 Lucee (Coldfusion) 组成,因此很多身份验证都是按照他们的文档手动完成的。尽管我确实使用了每个 SDK,因此我只需要担心对返回的 token 服务器端进行身份验证。
但是对于 Facebook,当用户已经在别处登录 FB 时,他们已经在 authorize
中。 SDK 在页面加载时初始化的状态。每当我选择“继续使用 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.
我明白错误说明了什么,为什么,但我不知道如何解决这个问题?从我发现的所有研究中,到处都声明将访问 token 传递给 API,但所有示例都使用 URL 端点使用
href
这样做。而不是 SDK 登录功能。这是可以通过他们的 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
});
最佳答案
再次查看 Facebook 文档并决定走存储访问 token 的路线,一旦创建以验证用户服务器端。而不是使用 Facebook SDK 来执行此操作,它不会重复登录过程、创建新的访问 token 并生成该错误。
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#token
关于javascript - 使用 JS SDK 将 access_token 传递给 FB.login(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59863945/