AWS Cognito:AWS.config.credentials 缺少 'get' 方法
AWS Cognito: Missing 'get' method for AWS.config.credentials
我正在构建一个将利用 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 }
});
对于那些感兴趣的人,我最终通过转换为 AWS.Credentials
解决了问题,如下所示:
(AWS.config.credentials as AWS.Credentials).get( (err) => { } )
我不是 TypeScript 专家,但这解决了编译器问题。
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
我正在构建一个将利用 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 }
});
对于那些感兴趣的人,我最终通过转换为 AWS.Credentials
解决了问题,如下所示:
(AWS.config.credentials as AWS.Credentials).get( (err) => { } )
我不是 TypeScript 专家,但这解决了编译器问题。
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