且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用户可以从我的mongodb数据库迁移到AWS Cognito用户池吗?

更新时间:2023-12-06 08:48:04

有几种方法可以实现,

  1. 您使用prepare .CSV文件并将其导入到aws cognito用户池中.导入过程将设置所有用户属性(密码除外). Cognito中的用户状态将为RESET_REQUIRED. Cognito强制重置密码.

  1. You use prepare .CSV file and import it in aws cognito user pool. Import process sets all user attributes except password. User's status in cognito will be RESET_REQUIRED. Cognito force to reset password.

否则,您可以编写一个脚本,该脚本将按照以下步骤将mongodb中的所有用户添加到cognito中,

Otherwise, you can write one script that will add all users from mongodb to cognito in following steps,

使用: AdminCreateUser

  1. 使用AWS管理控制台或调用AdminCreateUser API创建新的用户配置文件. 指定临时密码(将是您在mongodb中的用户密码),或允许Amazon Cognito自动生成一个.

  1. Create a new user profile by using the AWS Management Console or by calling the AdminCreateUser API. Specify the temporary password(will be your user's password in mongodb) or allow Amazon Cognito to automatically generate one.

指定是否将提供的电子邮件地址和电话号码标记为已为新用户验证. 通过AWS管理控制台为新用户指定自定义SMS和电子邮件邀请消息.

Specify whether provided email addresses and phone numbers are marked as verified for new users. Specify custom SMS and email invitation messages for new users via the AWS Management Console.

指定邀请消息是通过短信,电子邮件还是通过两者发送.

Specify whether invitation messages are sent via SMS, email, or both.

成功创建用户后,

  1. 使用相同的用户凭据对用户进行身份验证 使用:SDK调用InitiateAuth(Username,USER_SRP_AUTH)

  1. authenticate user using same user credentials Use: SDK calls InitiateAuth(Username, USER_SRP_AUTH)

在成功完成initateAuth之后,亚马逊Cognito会用Salt和amp; amp;返回PASSWORD_VERIFIER挑战.秘密区.

After success of initateAuth, amazon Cognito returns the PASSWORD_VERIFIER challenge with Salt & Secret block.

使用RespondToAuthChallenge(Username,,PASSWORD_VERIFIER

Use RespondToAuthChallenge(Username, , PASSWORD_VERIFIER

Amazon Cognito返回NEW_PASSWORD_REQUIRED挑战以及当前和必需的属性.

Amazon Cognito returns the NEW_PASSWORD_REQUIRED challenge along with the current and required attributes.

系统会提示用户,并输入新密码和必需属性的所有缺失值.

The user is prompted and enters a new password and any missing values for required attributes.

致电RespondToAuthChallenge(Username,,).

Call RespondToAuthChallenge(Username, , ).

成功更改密码后,用户可以使用在mongodb中添加的相同凭据登录.

After successful password change user can be able to login using same credentials added in mongodb.

注意:但是存在问题,如果您无法从mongodb解密用户凭据,那么第二种解决方案将无法工作.

Note: but there is problem, if you are not able to decrypt user credentials from mongodb then 2nd solution will not work.

-  In that case, you can specify the temporary password
(will  allow Amazon Cognito to automatically generate one.).

- all user users will be forced to change their password only at first login.

参考:

如果您想知道如何编写CSV并将其导入到cognito中,请检查此链接, https: //docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-using-import-tool-csv-header.html

If you want to know how to write CSV and import it in cognito then check this link, https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-using-import-tool-csv-header.html