问题描述
我正在尝试借助 this 教程创建 Web 应用程序身份验证.这是我写的代码 -
I am trying to create a Web App Authentication with help of this tutorial. Here is the code I have written -
var app = {};
app.configureCognito = function(){
AWSCognito.config.region = 'us-east-1';
var poolData = {
UserPoolId: 'userPoolId',
ClientId: 'ClientId'
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
UserName:'MyName',
Pool: userPool
};
var attributeList = [];
var dataEmail = {
Name: 'email',
Value: '[email protected]'
};
var dataPhoneNumber = {
Name: 'phone_number',
Value: '+9112212212212'
};
var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);
attributeList.push(attributeEmail);
attributeList.push(attributePhoneNumber);
var cognitoUser;
userPool.signUp('userName','password',attributeList,null,function(err,result){
if(err){
console.log(err);
alert(err);
return;
}
cognitoUser = result.user;
console.log('User Name is: '+cognitoUser);
});
};
我收到了配置中缺少凭据"的错误消息,我知道我们没有在此处执行任何 AWSCognito.config.credentials 分配,但它不应该使用 userPool 对象中提供的信息吗?代码有什么问题吗?丢失的部分还是什么?根据 UserPoolId 和 client id 所关注的两者都是 100% 正确的.任何帮助将不胜感激.
I am getting the error which says "missing credential in config", I understand that we are not doing any AWSCognito.config.credentials assignment here but isn't it supposed to use the information provided in userPool object? Is there anything wrong with the code any missing piece or something? As per the UserPoolId and client id are concerned both are 100% correct. Any help would be appreciated.
推荐答案
我显然是用下面的代码解决的,在这个例子中根本不需要提供 IdentityPoolId,这些只是占位符,可以留下如下-
I got it resolved by using below code apparently, there's no need to provide IdentityPoolId in this example at all, these are just the placeholders which can be left as below -
AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: '...'
});
AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: '...'
});
并且需要设置凭证 AWS.config.credentials 和 AWSCognito.config.credentials.一旦上述步骤完成,AWSCognito.config 需要更新如下 -
And both of the credential AWS.config.credentials and AWSCognito.config.credentials need to be set. Once the above steps complete the AWSCognito.config needs to be updated as below -
// Need to provide placeholder keys unless unauthorised user access is enabled for user pool
AWSCognito.config.update({accessKeyId: 'anything', secretAccessKey: 'anything'})
var poolData = {
UserPoolId : 'user pool id collected from user pool',
ClientId : 'application client id of app subscribed to user pool'
};
dataPhoneNumber 和 userData 是可选的,需要提供 dataPhoneNumber 以便注册时需要短信验证.
dataPhoneNumber and userData are optional, dataPhoneNumber should be provided in case sms verification for signup is required.
一旦上述问题就解决了,Identity-Code 是一个如果有人想看看它的工作模型.
The problem was resolved once the above were in place, Identity-Code is a working model if anyone want to have a look at it.
这篇关于Amazon Cognito 的用户池 - CredentialsError:配置中缺少凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!