Amazon Cognito 的用户池

编程入门 行业动态 更新时间:2024-10-05 17:22:15
本文介绍了Amazon Cognito 的用户池 - CredentialsError:配置中缺少凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试借助 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: 'mailme@mydomain' }; 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 的用户池

本文发布于:2023-11-28 04:26:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   Amazon   Cognito

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!