我正在使用 aws lambdas、dynamodb 和 cognito 构建身份验证系统。
我一直在比较 getOpenIdTokenForDeveloperIdentity() 提供的 token ;从服务器调用一个特定身份。
正在获取 token 和身份:
function getToken(email, fn) {
var param = {
IdentityPoolId: cognitoIdentityPoolId,
Logins: {} // To have provider name in a variable
};
param.Logins[cognitoDeveloperProvidedName] = email;
cognitoidentity.getOpenIdTokenForDeveloperIdentity(param,
function(err, data) {
if (err) return fn(err); // an error occurred
else fn(null, data.IdentityId, data.Token); // successful response
});
}
据我所知,我可以像这样从 cognito 获取已经生成的 token (而不是创建一个新 token ):
function checkToken(IdentityId, email, fn){
var param = {
IdentityPoolId: cognitoIdentityPoolId,
IdentityId: IdentityId,
Logins: {}
};
param.Logins[cognitoDeveloperProvidedName] = email;
cognitoidentity.getCredentialsForIdentity(param,
function(err, data) {
if (err) return fn(err);
else fn(null, data);
});
}
但我似乎无法让它工作
有什么想法吗?
最佳答案
明白了,checkToken 函数需要如下所示:
function checkToken(providedIdentity, token, fn){
var param = {
IdentityId: providedIdentity,
Logins: {}
};
param.Logins['cognito-identity.amazonaws.com'] = token;
cognitoidentity.getCredentialsForIdentity(param,
function(err, data) {
if (err) return fn(err);
else fn(null, data);
});
}
我需要将 cognito-identity.amazonaws.com 设置为登录提供商
关于javascript - 如何验证 getOpenIdTokenForDeveloperIdentity 认知 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36439585/