【问题标题】:AWS Cognito: Missing 'get' method for AWS.config.credentialsAWS Cognito:缺少 AWS.config.credentials 的“获取”方法
【发布时间】:2017-07-25 17:46:24
【问题描述】:

我正在构建一个使用 Cognito 用户池登录的 Angular2 应用程序。我能够成功验证用户身份;但是,无法获取经过身份验证的用户的访问密钥、密钥和会话令牌。

据我了解,我应该可以调用AWS.config.credentials.get( <callback> ),如下所示,但TypeScript 抱怨找不到get 方法(尽管我可以在aws-sdk 模块的类型声明中看到该方法)。

有什么想法吗?

// As part of authenticateUser - onSuccess callback...
var logins = {};
logins[`cognito-idp.${CognitoHelper.REGION}.amazonaws.com/${CognitoHelper.USER_POOL_ID}`] = session.getIdToken().getJwtToken();

// Add the user's token to the credential map
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: CognitoHelper.IDENTITY_POOL_ID,
  Logins: logins
});

// Get access keys
AWS.config.credentials.get( (error) => {  <-- .get method not found!
  if (error) { // do something }
});

【问题讨论】:

    标签: angular amazon-web-services amazon-cognito typescript2.0 aws-cognito


    【解决方案1】:

    对于那些感兴趣的人,我最终通过转换为AWS.Credentials 来解决,如下所示:

    (AWS.config.credentials as AWS.Credentials).get( (err) => { } )

    我不是 TypeScript 专家,但这解决了编译器问题。

    【讨论】:

      【解决方案2】:
      AWS.config.getCredentials(function (err) {
           if (err) console.log(err.stack); // credentials not loaded
           else console.log("Access Key:", AWS.config.credentials.accessKeyId);
      })
      

      https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#getCredentials-property

      【讨论】:

        猜你喜欢
        • 2017-06-05
        • 2021-10-15
        • 2018-02-27
        • 2016-12-05
        • 2020-10-03
        • 1970-01-01
        • 2018-03-28
        • 2020-10-23
        • 1970-01-01
        相关资源
        最近更新 更多