User Pools for Amazon Cognito - CredentialsError: Missing credentials in config

拥有回忆 提交于 2019-11-28 00:12:16

问题


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: 'mailme@mydomain.com'
    };

    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);
    });

};

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.


回答1:


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: '...' 
});

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 and userData are optional, dataPhoneNumber should be provided in case sms verification for signup is required.

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.



来源:https://stackoverflow.com/questions/37259824/user-pools-for-amazon-cognito-credentialserror-missing-credentials-in-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!