javascript - 如何验证 getOpenIdTokenForDeveloperIdentity 认知 token

标签 javascript amazon-web-services aws-lambda amazon-cognito

我正在使用 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/

相关文章:

javascript - 第 42 行的 fatal error : Call to a member function execute() on boolean in C:\xampp\htdocs\website\adduser. php

javascript - 如果我单击 document.body.addEventListener 中的任何子级、孙级(以及更深层次),如何单击父级标记

c# - 如何使用带有 Flowplayer 的 RTMP 从 Cloudfront 运行私有(private)内容视频

amazon-web-services - AWS Chalice-CI/CD-在同一网关下部署

go - 为什么 AWS API Gateway websocket 发送错误

javascript - d3.js-翻译<g>后如何添加<circle>

javascript - 当电子邮件字段未填写时显示 Bootstrap 警报

amazon-web-services - 在 terraform 对象中使用输出值

amazon-web-services - 如何设置 API 网关与私有(private) NLB 通信?

aws-lambda - 代码管道: Read data from previous step