使用确认 URL 确认 amazon cognito 后如何重定向? [英] How to redirect after confirm amazon cognito using confirmation URL?
问题描述
我想在用户在 amazon cognito 中确认后重定向到特定的 url.
I want to redirect to a specific url after the user confirmation in amazon cognito.
当用户注册时,他将收到带有验证链接的确认邮件,如下所示https://<>.auth.us-west-2.amazoncognito.com/confirmUser?client_id=<<>>&user_name=<<>>&confirmation_code=<<>>
When a user sign up he will get confirmation mail with a verification link as follows https://<>.auth.us-west-2.amazoncognito.com/confirmUser?client_id=<<>>&user_name=<<>>&confirmation_code=<<>>
如果用户点击上面的链接,它将重定向到确认页面.
If the user clicks the above link it will redirect to confirmation page.
完成用户确认后,页面应重定向到我的应用程序.
Once the user confirmation is completed the page should redirect to my application.
请给我一些解决这个问题的想法.
Please give me some idea to solve this problem.
推荐答案
目前,无法使用电子邮件中的验证链接完成此重定向.不久前,我尝试将 redirect_uri 添加到验证 URL,但它们不起作用.
Currently, this redirection can't be done using verification link in email. I tried adding redirect_uri to the verification URL a while back but they do not work.
解决方法
- 在 Api 网关中创建一个 API,它接受这 3 个参数和一个额外的 redirect_uri 参数.在后端 lambda 中,使用参数 & 向实际链接发出 GET 请求.确认用户.成功后,使用 redirect_uri 作为参数从您的 API 返回 302 重定向.
- 在您的用户池中,使用自定义消息触发器构建指向 API 网关 api 的链接,而不是默认的 Cognito url
- 因此,验证链接将类似于:https://myapi.abc.com/confirm?client_id=somevalue&user_name=some_user&confirmation_code=some_code&redirect_uri=https://myapp.com
这些值被传递到后端 lambda,后者向 https://your_domain.auth.us-west-2.amazoncognito.com/confirmUser?client_id=somevalue&user_name=some_user&confirmation_code=some_code
成功后,从您的 API 网关返回 302 https://myapp.com
On success, return 302 https://myapp.com from your API Gateway
我知道对于这样一个简单的要求,这是一个复杂的解决方法.最好的方法是提出功能请求,并希望他们支持 Cognito URL 中的 redirect_uri.
I know this is a convoluted workaround for such a simple requirement. The best way would be to raise a feature request and hope they support a redirect_uri in the Cognito URL.
编辑
为了节省 lambda 成本,您还可以在 API 中使用 HTTP 端点并向 cognito 服务端点.示例:
To save your lambda costs, you could also use an HTTP endpoint in your API and make a request to the cognito service endpoint for your region. Example:
POST HTTP/1.1
Host: cognito-idp.us-east-1.amazonaws.com
x-amz-target: AWSCognitoIdentityProviderService.ConfirmSignUp
Content-Type: application/x-amz-json-1.1
{
"ClientId":"xxxxxxxxxxxxx",
"ConfirmationCode":"123456",
"Username":"username"
}
这篇关于使用确认 URL 确认 amazon cognito 后如何重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!