Getting Error 400: redirect_uri_mismatch in cognito idp settings

Viewed 465

I am following this cognito add social auth to add google auth into one of my app for testing. Completed all steps as listed, but when I am testing that using this https://<your_user_pool_domain>/login?response_type=code&client_id=<your_client_id>&redirect_uri=https://www.example.com , I am getting an error

Error 400: redirect_uri_mismatch
The redirect URI in the request, https://xxxx-xxxx.auth.ap-south-1.amazoncognito.com/oauth2/idpresponse, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit:

initially the redirect uri and callback url in cognito app client settings were different but i changed those, also I tried changing my redirect url to simple https://google.com, but still not working. I did some research regarding the same, found out that it might take some time to reflect the changes in google oauth setings, its been 2 hrs since I have changed the same, should I wait or is there some other work around this. Also, I setup facebook login following same doc, it is working fine. please help!

3 Answers

In my experience this mismatch refers to the difference between your constructed URL and the setting in Cognito Pool. In the pool config, the redirect_uri is called Callback URL. Make sure those two have the same URL.

You can set it in Cognito UI here: App Integration > App Client Settings > Sign in and sign out URLs > Callback URL(s)

or you can specify the URL(s) in your code if you are using CDK.

new cognito.UserPoolClient({
  oAuth: {
    callbackUrls: ['https://www.example.com', '<url2>'],
  }
  ...
}

Finally I got the solution, redirect url in google auth credentials needs to be your **domainName+/oauth2/idpresponse** .

its has something to do with your uri, whether in google cloud or cognito ,double check if the uri entered is a match

Related