【发布时间】:2019-08-01 00:02:22
【问题描述】:
在我尝试将存储在 MongoDB 数据库中的用户帐户与 Alexa 的帐户链接功能连接后,确认页面显示“我们此时无法链接 *”。
我运行的 OAuth2 服务器由本教程组成:Building a RESTful API With Node — OAuth2 Server
整个身份验证流程运行正常,甚至访问令牌(称为值)也存储在我的数据库中。
我认为这是最重要的代码块,因为我认为一切正常。
server.exchange
server.exchange(oauth2orize.exchange.code(function(client, code, redirectUri, callback) {
Code.findOne({ value: code }, function (err, authCode) {
if (err) { return callback(err); }
if (authCode === undefined) { return callback(null, false); }
if (client._id.toString() !== authCode.clientId) { return callback(null, false); }
if (redirectUri !== authCode.redirectUri) { return callback(null, false); }
// Delete auth code now that it has been used
authCode.remove(function (err) {
if(err) { return callback(err); }
// Create a new access token
var token = new Token({
value: uid(256),
clientId: authCode.clientId,
userId: authCode.userId
});
// Save the access token and check for errors
token.save(function (err) {
if (err) { return callback(err); }
callback(null, token);
});
});
});
}));
这些是我的 nginx 访问日志:
77.182.19.18 - dmnktoe [10/Mar/2019:15:12:27 +0100] "GET /api/oauth2/authorize?redirect_uri=https://layla.amazon.com/api/skill/link/*&client_id=amazonEchoServices&response_type=code&state=*very-long-state-value* HTTP/1.1" 200 525
77.182.19.18 - dmnktoe [10/Mar/2019:15:12:29 +0100] "POST /api/oauth2/authorize HTTP/1.1" 302 1520 "https://oauth2.healform.de/api/oauth2/authorize?redirect_uri=https://layla.amazon.com/api/skill/link/*&client_id=amazonEchoServices&response_type=code&state=*very-long-state-value*"
54.240.197.10 - amazonEchoServices [10/Mar/2019:15:12:29 +0100] "POST /api/oauth2/token HTTP/1.1" 200 434 "-" "Apache-HttpClient/4.5.x (Java/1.8.0_192)"
希望任何人都可以提供帮助。
更新:有点好笑,但 Amazon/Alexa 所需要的只是我的令牌对象中的值。所以 callback(null, token);变成了回调(null, token.value);.
【问题讨论】:
标签: javascript node.js mongodb oauth alexa