我正在构建一个 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/