【问题标题】:Cannot fetch the authentity token from AWS无法从 AWS 获取身份验证令牌
【发布时间】:2021-04-21 12:16:00
【问题描述】:

我想从 AWS 获取身份验证令牌; 但是,我只收到一条错误消息告诉我 客户端 ID 不正确。

我很高兴在网上找到了这段代码, 链接:https://docs.aws.amazon.com/cognito/latest/developerguide/authentication.html 我能够调用最后一个函数调用, 但它抱怨ClientId,我不知道 从哪里获取 Clientid :-(

我不确定从哪里获取客户端 ID 和用户池 ID?

AWS 网站上还有一个 Client App Id。

我正在寻找我只需要提供的东西 使用 node js 的用户名和密码?


const AmazonCognitoIdentity = require('amazon-cognito-identity-js');

var authenticationData = { 用户名 : '...', 密码 : '...', };

var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);

var poolData = { 
    UserPoolId : '...', // From where on the AWS web site can I fetch the correct User Pool Id?
    ClientId : '...' // From where on the AWS web site can I fetch the correct client Id?
};

var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

var userData = {
    Username : 'karlschmitt',
    Pool : userPool
};

var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

   
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        var accessToken = result.getAccessToken().getJwtToken();

        /* Use the idToken for Logins Map when Federating User 
        Pools with identity pools or when passing through an 
        Authorization Header to an API Gateway Authorizer */
        var idToken = result.idToken.jwtToken;
        console. log("Successful!");
    },

    onFailure: function(err) {
        // alert(err);
        console. log("Failure!" + err.message);
    },

});

【问题讨论】:

    标签: amazon-web-services authentication token amazon-cognito


    【解决方案1】:
    • 创建 Congnito 用户池 - Here 是一个链接并从常规设置中获取 Pool Id
    • 将您的应用程序注册为客户端 - Here 是一个链接并获取 client id

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 2021-01-23
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多