Raj*_*Raj 8 amazon-web-services ios amazon-cognito aws-lambda
我开始为我的虚拟ios应用程序探索AWS Cognito,尽管在新用户注册期间我在电子邮件中收到确认链接,然后单击该链接可以正确验证电子邮件。
我们是否具有忘记密码的相同功能,即获取链接而不是代码,并将其重定向到我的虚拟网站,仅用户需要输入新密码即可。
提前致谢。
小智 8
我有可能在我的项目中实现了这一目标。
它是通过aws cognito中的触发器完成的。
在要触发的自定义消息触发器中设置lambda函数。
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
var CustomMessage_ForgotPassword = `<style>
p {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
}
</style>
<div id=":x9" class="a3s aXjCH " role="gridcell" tabindex="-1"><p>Hello,</p>
<p>Follow this link to reset your Password. </p>
<p><a href="https://your-website.com/reset-password?confirmation_code=${event.request.codeParameter}&user_name=${event.userName}"> Reset Password </a></p>
<p>If you didn’t ask to change password, you can ignore this email.</p>
<p>Thanks,</p>
<p>Your website team</p>
</div>`
if (event.triggerSource === "CustomMessage_ForgotPassword") {
event.response.emailMessage = CustomMessage_ForgotPassword;
}
callback(null, event);
};
Run Code Online (Sandbox Code Playgroud)
然后在您的网站上进行一条处理该代码的路由。
我忘记了几个月前我问过的这个问题,想用答案更新它。因此,根据 AWS 文档:
“调用此 API 会导致向最终用户发送一条消息,其中包含更改用户密码所需的确认代码。对于用户名参数,您可以使用用户名或用户别名。如果用户存在已验证的电话号码,则向该电话号码发送确认码。否则,如果存在已验证的电子邮件,则向该电子邮件发送确认码。如果已验证的电话号码和已验证的电子邮件均不存在,则 InvalidParameterException 为抛出。”
这是 AWS 文档的链接。
因此,可能有一些解决方法来实现它,但 AWS Cognito 目前不支持为忘记密码发送自我验证链接。
是。您可以调用ForgotPassword端点:
{
"AnalyticsMetadata": {
"AnalyticsEndpointId": "string"
},
"ClientId": "string",
"SecretHash": "string",
"Username": "string"
}
Run Code Online (Sandbox Code Playgroud)
然后,您需要拨打电话(从您的网站代码)到ConfirmForgotPassword端点以重置密码:
{
"AnalyticsMetadata": {
"AnalyticsEndpointId": "string"
},
"ClientId": "string",
"ConfirmationCode": "string",
"Password": "string",
"SecretHash": "string",
"Username": "string"
}
Run Code Online (Sandbox Code Playgroud)
我知道这个问题已经得到回答和接受,虽然 Cognito 确实没有开箱即用,但我想找到一种方法让它无缝地工作。
这是我想出的:
CognitoUser实例并forgotPassword在用户上调用该函数。CognitoUser实例并调用该confirmPassword函数。对此有何想法?我使用了相同类型的机制来让用户注册以无缝方式工作,尽管这需要做更多的工作。
| 归档时间: |
|
| 查看次数: |
3887 次 |
| 最近记录: |