angular - AWS Cognito : Missing 'get' method for AWS. config.credentials

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

我正在构建一个 Angular2 应用程序,它将利用 Cognito 用户池登录。我能够成功验证用户身份;但是,无法获取经过身份验证的用户的访问 key 、 secret key 和 session token 。

据我了解,我应该可以调用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 }
});

最佳答案

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

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

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

关于angular - AWS Cognito : Missing 'get' method for AWS. config.credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615760/

相关文章:

typescript2.0 - 如何在 Typescript 中使用 VueJS?

angular - ng-model 可以更新模型中的对象吗?

angular - ionic 4 - Angular 6 : How to control Ionic router history to stop cache a view component?

javascript - 在 Angular2 应用程序中从 jquery 跨 mouseenter 事件传递 JS 变量

postgresql - 需要要求 AWS RDS 上的 Postgres 用户使用密码登录

angular - 错误 TS2349 : Cannot invoke an expression whose type lacks a call signature

angular - 为什么在代码更改后分页器页面索引不会更改?

angular - 使用 Service Worker 预取 API 调用

amazon-web-services - AWS VPC 对等互连和路由表

amazon-web-services - 如何防止EC2实例立即终止?