【发布时间】:2018-01-07 09:26:50
【问题描述】:
我正在使用 Cognito 用户池和 Cognito 联合身份将 IAM 角色传递给经过身份验证和未经身份验证的用户。当我尝试将用户从未经身份验证切换到经过身份验证时,开发人员控制台不会记录更改已发生;这表明我有 100% 未经身份验证的用户。
现在我将我的 AWS 客户端实例化为未经身份验证的用户,然后调用一个函数来更新可用的凭证,以便我可以将它们切换为经过身份验证的用户。例如:
AWS.config.region = 'us-west-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: identityPoolId,
region: 'us-west-2',
Logins: {}
});
const updateCredentials = () => {
const auth = store.getState().auth; //this gets the authentication credentials from a global store.
AWS.config.credentials.Logins = {
'cognito-idp.us-west-2.amazonaws.com/us-west-2_XXXXXXXXX': auth.idToken
};
AWS.config.credentials.expired = true;
};
据我所知,这是正确的方法。请参阅文档at the bottom of this page、here 和here。
但是,我的控制台显示我没有经过身份验证的用户,因此updateCredentials 没有将用户切换到经过身份验证的用户。有什么办法可以解决这个问题?
【问题讨论】:
标签: javascript amazon-web-services amazon-cognito