【发布时间】:2015-12-13 06:31:51
【问题描述】:
我正在使用开发人员身份验证的身份通过客户端浏览器上的 Cognito 进行身份验证。当我的页面加载(或刷新)时,我希望我的应用程序记住身份,只要对象没有过期(我认为它会持续大约一个小时)。但是,我不知道如何从 Cognito 中检索身份,而无需再次通过开发者身份验证。
这是代码在页面加载时的作用:
var cognitoCredentials
$(document).ready(function() {
"use strict";
cognitoParams = {
IdentityPoolId: 'us-east-1:xxxxxxx'
};
cognitoCredentials = new AWS.CognitoIdentityCredentials(cognitoParams);
AWS.config.credentials = cognitoCredentials;
});
并且通过开发者认证登录后:
cognitoCredentials.params.IdentityId = output.identityId;
cognitoCredentials.params.Logins = {
'cognito-identity.amazonaws.com': output.token
};
cognitoCredentials.expired = true;
如果我已经登录,然后刷新页面,然后再次尝试登录,我会收到一个错误,当我已经拥有身份时,我正在尝试获取身份
Error: Missing credentials in config(…) NotAuthorizedException: Missing credentials in config
"Access to Identity 'us-east-1:xxxxxxx' is forbidden."
但是,我不知道如何访问它。如何检索凭据,以便在刷新页面时能够检测到 Cognito 之前提供的身份?
【问题讨论】:
标签: javascript amazon-web-services amazon-cognito