Amazon Cognito的用户池-CredentialsError:配置中缺少凭据 [英] User Pools for Amazon Cognito - CredentialsError: Missing credentials in config

查看:294
本文介绍了Amazon Cognito的用户池-CredentialsError:配置中缺少凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在的帮助下创建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: '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);
    });

};

我收到错误消息,提示配置中缺少凭据,我知道我们没有这样做这里有任何AWSCognito.config.credentials分配,但是它不应该使用userPool对象中提供的信息吗?代码中是否有任何遗漏的地方?根据UserPoolId和客户端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:配置中缺少凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆