Search code examples
amazon-cognito

Find Signed up User from redirect of AWS Cognito Hosted UI


I want to know which user has signed up on my Cognito hosted UI. I configured everything accordingly to the AWS documentation.

When opened, the UI works just fine. As soon as it comes to the redirect to my website it appends a UUID code like this:

https://example.com/signup?code=140ac1a7-aaaa-bbbb-cccc-180bcb7c55f0

But it seems that the given code has nothing in common with the user that was just created. Where am I missing something?

Additional info: I'm working on a java backend, so I cannot use the JS SDK

I tried to change the response_type to token instead of code but then the hosted UI redirects me to:

https://example.com/signup?#error_description=unauthorized_client&error=invalid_request


Solution

  • The UUID is the access code. With it u can get the access token which can provide you with the user information. The documentation can be found here: https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html

    And the request looks like this:

    POST https://your-pool.auth.your-region.amazoncognito.com/oauth2/token
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=authorization_code&
    client_id=your-code&
    code=the-access-code&
    redirect_uri=your-redirect