How to redirect after confirm amazon cognito using confirmation URL?

前端 未结 4 1622
花落未央
花落未央 2020-12-24 14:10

I want to redirect to a specific url after the user confirmation in amazon cognito.

When a user sign up he will get confirmation mail with a verification link as fol

4条回答
  •  感情败类
    2020-12-24 14:52

    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.

    Workaround

    • Create an API in Api gateway which takes these 3 parameters and an additional redirect_uri parameter. In the backend lambda, make a GET request to the actual link using the parameters & confirm the user. On success, return a 302 redirect from your API using the redirect_uri as parameter.
    • In your userpool, use the custom message trigger to build a link to your API gateway api instead of the default cognito url
    • So, verification link would be something like: https://myapi.abc.com/confirm?client_id=somevalue&user_name=some_user&confirmation_code=some_code&redirect_uri=https://myapp.com
    • These values are passed to backend lambda which makes a GET request to https://your_domain.auth.us-west-2.amazoncognito.com/confirmUser?client_id=somevalue&user_name=some_user&confirmation_code=some_code

    • On success, return 302 https://myapp.com from your API Gateway

    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.

    EDIT

    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"
    }
    

提交回复
热议问题