javascript – 如何验证getOpenIdTokenForDeveloperIdentity cognito令牌
作者:互联网
我正在使用aws lambdas,dynamodb和cognito构建一个身份验证系统.
我坚持比较getOpenIdTokenForDeveloperIdentity()提供的令牌;从服务器调用一个特定标识.
获得令牌和身份:
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(而不是创建一个新的)获取已经生成的令牌,如下所示:
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,amazon-web-services,aws-lambda,amazon-cognito 来源: https://codeday.me/bug/20190628/1311992.html