AWS Cognito 管理员创建的用户临时密码验证和重置

Har*_*rsh 5 javascript amazon-web-services amazon-cognito aws-sdk aws-lambda

我正在尝试使用 AWS Cognito 生成临时密码来验证管理员通过密码重置挑战创建的用户,但我找不到有关如何使用临时密码并在 javascript 中为新用户设置新密码的方法或示例.

Joe*_*sca 5

Amazon Cognito 开发人员指南提供了使用临时密码进行身份验证并处理该newPasswordRequired情况的示例:

\n\n
cognitoUser.authenticateUser(authenticationDetails, {\n    onSuccess: [...],\n    onFailure: [...],\n    mfaRequired: [...],\n    newPasswordRequired: function(userAttributes, requiredAttributes) {\n        // User was signed up by an admin and must provide new \n        // password and required attributes, if any, to complete \n        // authentication.\n\n        // userAttributes: object, which is the user\'s current profile. It will list all attributes that are associated with the user. \n        // Required attributes according to schema, which don\xe2\x80\x99t have any values yet, will have blank values.\n        // requiredAttributes: list of attributes that must be set by the user along with new password to complete the sign-in.\n\n\n        // Get these details and call \n        // newPassword: password that user has given\n        // attributesData: object with key as attribute name and value that the user has given.\n        cognitoUser.completeNewPasswordChallenge(newPassword, attributesData, this)\n    }\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

摘自此处的指南:https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html

\n\n

completeNewPasswordChallenge请注意,示例中的第三个参数是this,即具有处理函数的对象。这是因为completeNewPasswordChallenge需要onSuccessonFailure处理程序,并且您通常可以使用与authenticateUser结果相同的处理程序。

\n