Cognito redirect_mismatch Error: Fix the Callback URL

Logeshwaran
—

Amazon Cognito "redirect_mismatch" means the redirect_uri your app sent to the login page is not on the list of Allowed callback URLs for the app client named in that same request. Cognito compares the two as strings, character for character: scheme, host, port, path, case and trailing slash. To fix it, copy the exact redirect_uri out of the browser's own request, compare it with the app client's callback list, and make the two identical, either by registering the real URL or by correcting the app. Here is the part that costs people an evening: adding the URL to Allowed sign-out URLs fixes nothing. It is a different list for a different redirect, and the console puts the two side by side as if they were interchangeable.

Jake's phone repair shop has a small booking dashboard for staff, and Ethan built its login on Cognito so nobody had to store passwords. It worked for months. Then a new laptop, a fresh checkout, a different port, and the login page threw redirect_mismatch at the one person who needed to book a repair before opening time. Jake read his config file ten times and swore the URL was right. It was. The browser was sending a different one. This page is the order Ethan used to sort it out: how to read what the browser actually sent, the exact-match rules that turn one slash into an error, where the five lookalike errors come from, and the fixes for localhost, Amplify, an Application Load Balancer, and a login that goes through Google or a corporate identity provider.

⚡ Quick answer

• Read the real request: browser Developer Tools → Network → the /oauth2/authorize request → the decoded client_id and redirect_uri.

• Console: Cognito → User pools → your pool → App clients → the client with that ID → login pages → Allowed callback URLs. Make it match exactly.

• CLI, read-only: aws cognito-idp describe-user-pool-client --user-pool-id us-east-1_EXAMPLE --client-id EXAMPLECLIENT and read CallbackURLs.

• Localhost: the port and path must match too; http://localhost:5173/auth/callback is not http://localhost:3000/.

• ALB: the callback is https://your-host/oauth2/idpresponse, in lowercase, on the client the listener uses.

• Different error after the fix (invalid_client, invalid_grant, invalid_scope)? That is the next step failing, not the fix undone. Each has its own section below.

Five errors, two endpoints: which step actually failed

Cognito's login is a two-step handshake, and the error tells you which step broke if you know where each one lives. Step one is the browser visiting /oauth2/authorize, which shows the login page and sends the user back to your app with a code. Step two is your app, or the library inside it, posting that code to /oauth2/token to exchange it for tokens. Sign-out is a third door, /logout. People search for these as one bundle of Cognito error codes, and treating them as one bundle is the costly mistake, because each points at a different check.

ErrorWhere it happensWhat it means in one lineLook at
redirect_mismatch/oauth2/authorizeThe redirect_uri is not registered on this app clientThe authorize request and CallbackURLs
invalid_request/oauth2/authorizeThe request is malformed: no response_type, or a code_challenge without its methodThe query string itself
invalid_client/oauth2/tokenClient authentication failed: wrong ID, wrong secret, or a secret for a different clientThe token request's credentials
invalid_grant/oauth2/tokenThe code was already used or does not exist, a refresh token was revoked, or a scope needs an attribute the client cannot readHow your callback handler spends the code
invalid_scopeEither endpointA scope is unknown or malformed, or names a resource server that does not existThe scope list and the app client's allowed scopes

One more that deserves its own line, because it looks like a redirect problem and is not. If the redirect_uri in the token request differs from the one used at authorize, Cognito answers unauthorized_client with an error_description of invalid_redirect. Registration alone is not enough at that step; the two values have to be the same string. Keep that one in mind for the token section.

Jake: "The booking app says redirect mismatch, but my other app signs in fine. Doesn't that prove the user pool is okay?"

Ethan: "It proves the other app's request is accepted. Cognito checks the callback against the client ID in this request. Compare that pair, and leave the user pool alone."

The exact-match rules: a slash is a different string

This is the part that feels petty until it saves your evening. Cognito compares strings, not intentions. A URL has a scheme before the ://, a host, sometimes a port, and a path, and every one of them has to match the registered entry exactly.

Registered callbackWhat the browser sentWhy it fails
https://app.example.com/callbackhttps://app.example.com/callback/Trailing slash
https://app.example.com/callbackhttp://app.example.com/callbackScheme, and plain HTTP is refused outside localhost anyway
http://localhost:3000/callbackhttp://localhost:5173/callbackPort
https://app.example.com/Authhttps://app.example.com/authPath case
https://app.example.com/callbackhttps://www.app.example.com/callbackHost
https://app.example.com/callbackhttps://app.example.com/Path

The rules behind the table come straight from the app client API. A callback must be an absolute URI, it must already be registered on that client, and it cannot carry a fragment such as #section. It must use HTTPS, with three exceptions for testing: http://localhost, http://127.0.0.1 and http://[::1], with any port you like. App-style callbacks such as myapp://example are allowed too. An app client can hold up to 100 callback URLs, so there is never a reason to squeeze two environments into one entry, and that localhost exception is for development only; an ordinary production HTTP redirect is still refused.

Adding a fragment or a wildcard to "make it work everywhere" makes it work nowhere: a fragment is rejected outright, and a wildcard is not something an exact-match check knows how to read. Register the real development callback and the real production callback, spelled the way the application actually sends them, and keep the spelling canonical in the app. For an Application Load Balancer the documented callback must be all lowercase, which is one more reason to stop relying on case being forgiven.

Thirty seconds in the Network tab usually ends the argument

Jake: "I have read my config file ten times. The URL is right."

Ethan: "Your config file is right. The question is what the browser actually sent, and the Network tab is the only place that tells you. Thirty seconds there usually ends the argument."

Your config is what you intended. The browser's request is what Cognito received. When a framework builds the authorize URL from environment variables, or an identity provider redirects you twice, the two can drift without anyone editing anything. The Network panel shows the drift.

  1. Open the app in a fresh tab and open Developer Tools, usually F12.
  2. Choose Network and turn on Preserve log, so the redirect does not wipe the request you need.
  3. Click the login button once. Filter for authorize, oauth2, or your Cognito domain.
  4. Open the GET to /oauth2/authorize and read the decoded query parameters.
  5. Copy the actual client_id and redirect_uri, not the ones you expected.
  6. Compare that decoded redirect_uri with the app client's CallbackURLs, fix whichever side is wrong, and start a fresh login.

A real request looks like this, with the callback percent-encoded, which is normal.

https://example-domain.auth.us-east-1.amazoncognito.com/oauth2/authorize?
client_id=EXAMPLECLIENT&response_type=code&scope=openid%20email&
redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback&state=RANDOM_OPAQUE_VALUE

Decoded, that callback is https://app.example.com/auth/callback. Compare decoded values, and also look for double encoding, where an app encodes an already-encoded URL and Cognito receives text that is not your URL at all. If you never see an authorize request, the app is failing before it reaches Cognito, opening a different window, or going straight to an identity provider, and that is the request to debug instead. Jake's answer was on line one: client_id was the production client, because his new checkout had copied a production environment file, and the callback was a localhost port the production client had never heard of.

⚠ Before you paste a screenshot anywhere

The Network panel shows authorization codes, state values, cookies and sometimes tokens. Redact them. A copied authorization code has no place in a public ticket.

Finding the right app client, and reading it without touching it

A user pool can hold several app clients: one for local work, one for production, one for a load balancer. The callback list belongs to the client, so editing a similar-looking client in the right pool is still the wrong change. Start from the client_id you just copied.

  1. Open Amazon Cognito in the Region where the pool lives.
  2. Choose User pools, then the pool.
  3. Open App clients and pick the one whose ID matches the browser's client_id.
  4. Open its login pages or managed login settings and read Allowed callback URLs and Allowed sign-out URLs as two separate lists.
  5. Add the legitimate callback or fix the app, save, and try a fresh login.

The console's labels have moved around over the years. The thing that does not move is the client's CallbackURLs field in the API, and the CLI reads it without changing anything.

aws sts get-caller-identity
aws cognito-idp describe-user-pool-client --user-pool-id us-east-1_EXAMPLE --client-id EXAMPLECLIENT --region us-east-1 \
  --query "UserPoolClient.{CallbackURLs:CallbackURLs,LogoutURLs:LogoutURLs,Scopes:AllowedOAuthScopes,Flows:AllowedOAuthFlows}"

If the client ID is not in the pool you are looking at, check the app's environment variables and the Cognito domain it uses. Copying a production client ID into development gets you past the error and into a worse one later. The identity provider has its own callback into Cognito, a different hop entirely, so leave it alone when it is your application's callback that differs.

When you do need to change a client from the CLI, be careful with update-user-pool-client: it replaces settings you did not mention with defaults, so describe the client first, keep the OAuth flows, scopes, providers and token settings in your infrastructure code, and apply the whole desired configuration. If CloudFormation, CDK, Terraform or an Amplify backend owns the client, fix it there, or your console edit will be undone on the next deploy. Make the emergency change if you must, then backport it the same day.

Localhost: ports, loopback addresses, and a server that moved

Jake: "It works on my machine on port 3000. My colleague's copy runs on 5173 and fails."

Ethan: "Then your colleague's redirect is a different string. Register the port they actually use on the development client, and leave production alone."

Local development makes this error more than anything else, because frameworks pick ports. A React app on 3000, a Vite app on 5173, a backend on 8080: each is a different callback. http://localhost:5173/auth/callback has to be registered as exactly that; http://localhost:5173/ is not a substitute, and localhost and 127.0.0.1 are different strings even though both reach your machine. Cognito allows all three loopback forms with custom ports, so register the ones your team really uses on the development client, and no more.

Two quiet causes. A dev server that finds its preferred port busy starts on the next one and tells you in the terminal, which nobody reads; the browser's address bar shows the real port. And a reverse proxy that upgrades local HTTP to HTTPS or rewrites a path changes the public URL the browser carries to Cognito. The callback has to be the address the browser can actually return to.

Callback URLs and sign-out URLs are different lists

If you added the URL, saved, retried, and got the same error, there is a fair chance you added it to the wrong list. The two lists sit next to each other in the console and look interchangeable. They are not. The callback list says where Cognito may send a user after sign-in. The sign-out list says where it may send the browser after a /logout request that carries logout_uri.

You want toRequestThe list that must contain the URL
Sign in and return to the app/oauth2/authorize?redirect_uri=...Allowed callback URLs
Sign out to a landing page/logout?client_id=...&logout_uri=...Allowed sign-out URLs
Sign out, then show the login page again/logout?redirect_uri=... plus the login parametersAllowed callback URLs, because that redirect is a post-sign-in URL

That third row is the one that trips people. A redirect_uri on a logout request is not a sign-out landing page; it is passed through to the login page as the place to go after the user signs in again. And if a logout request carries both logout_uri and redirect_uri, Cognito uses logout_uri and ignores the other. So https://app.example.com/goodbye belongs in the sign-out list, and a callback URL that only exists in the sign-out list will never satisfy an authorize request.

Amplify: fix the redirect where it is generated

Amplify builds the authorize request for you, which is lovely until one redirect lives in your source, another in generated configuration, and a third on the app client. The browser's request is the referee. Different Amplify generations use different configuration shapes, so match the one your installed library expects rather than an old snippet from a forum. This is the shape for current Amplify JavaScript, with placeholders, not working pool values.

import { Amplify } from "aws-amplify";
Amplify.configure({
  Auth: { Cognito: {
    userPoolId: "us-east-1_EXAMPLE",
    userPoolClientId: "EXAMPLECLIENT",
    loginWith: { oauth: {
      domain: "example-domain.auth.us-east-1.amazoncognito.com",
      scopes: ["openid", "email"],
      redirectSignIn: ["http://localhost:5173/auth/callback"],
      redirectSignOut: ["http://localhost:5173/"],
      responseType: "code"
    } }
  } }
});

redirectSignIn must match a callback on the client; redirectSignOut must match a sign-out URL. When several callbacks are listed, the first element of that array is not guaranteed to be the one your deployed domain gets; read the redirect_uri the browser sends and make the routing explicit. An Amplify Gen 2 project generates its configuration from the backend definition, and others read amplify_outputs.json; editing a generated file by hand only lasts until the next deployment regenerates it. Change the persistent backend or client configuration, redeploy, and read the new authorize request.

signInWithRedirect() starts the browser flow. Getting the browser back to the right URL is only half the job; the app still has to finish processing the result and establish a session. If the browser lands on the right URL and a token error follows, that is the token sections below, not another callback edit.

Jake: "Would it be easier to add every staging URL we might ever use?"

Ethan: "Only add destinations you control and actually use. A callback is where the login result goes. Getting the string right is part of protecting it, not paperwork."

ALB and Cognito: the callback is /oauth2/idpresponse, in lowercase

When an Application Load Balancer signs users in with Cognito, the load balancer is the OAuth client, and it receives the callback, not your application. The callback is the public hostname users actually visit, followed by /oauth2/idpresponse: https://ALB-DNS-NAME/oauth2/idpresponse for the AWS-generated name, or https://app.example.com/oauth2/idpresponse for your alias. One rule bites: the callback in the app client must be all lowercase. Registering only https://app.example.com/ is not enough; ALB authentication will not quietly rewrite it to the listener's callback path for you.

  1. In EC2 → Load Balancers, open the HTTPS listener and read the Authenticate with Cognito action: which pool, which app client.
  2. In the browser, read the authorize request; its redirect_uri should be your public host plus /oauth2/idpresponse.
  3. On that exact app client, add the lowercase HTTPS callback with the hostname users visit. If they can reach the ALB by both its alias and its AWS name, register both.
  4. Check the client has a secret, uses the code grant, and allows the openid scope, because the listener needs an ID token and aws.cognito.signin.user.admin alone does not produce one.
  5. Start a fresh login. A user has 15 minutes to finish it, or the load balancer answers 401 and they start again.

Editing the target group health check will not touch an ALB redirect mismatch; health checks and OAuth return addresses are different things. And federation adds a hop: if Cognito sends the user on to Google or a corporate provider, that provider returns to Cognito at /saml2/idpresponse or the OIDC equivalent, and Cognito returns to the ALB at /oauth2/idpresponse. Putting the ALB path on the identity provider breaks the wrong hop.

invalid_client: the token step could not prove who the app is

invalid_client comes from /oauth2/token, and it means client authentication failed. The browser coming back successfully rules out a redirect mismatch; this one lives at the token step. For a client that has a secret, Cognito accepts the ID and secret as HTTP Basic authentication or in the POST body, and a wrong ID, a wrong secret, or the right secret for a different client all produce the same answer.

A public browser app normally uses a client without a secret and the code grant with PKCE, which ties the code to the browser that started the flow without shipping a secret in JavaScript. A backend can keep a secret safely; a front end cannot. If you created a secret-bearing client and are trying to redeem codes from browser code, choose a public client or move the exchange to a backend. A client secret in a source map, a public environment variable, or a browser bundle is no longer a secret.

curl -X POST "https://example-domain.auth.us-east-1.amazoncognito.com/oauth2/token" \
  --user "EXAMPLECLIENT:REPLACE_WITH_SECRET" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=authorization_code" \
  --data-urlencode "code=FRESH_AUTHORIZATION_CODE" \
  --data-urlencode "redirect_uri=https://app.example.com/auth/callback"

That is the shape of a confidential client's exchange, with placeholders, and it belongs in a protected environment because command lines end up in shell history. If the error persists, compare the client ID at authorize with the one authenticating at the token endpoint, check whether a staging secret was deployed to production or an old secret survived a client replacement, and make sure the request goes to the right user pool domain; a perfectly good secret for another pool authenticates nothing here.

invalid_grant: a code spent twice, or a scope the client cannot read

Jake: "The login works now, but refreshing the page throws invalid_grant."

Ethan: "That is your app trying to spend the same code twice. The callback did its job; now the handler needs to run once and move the user to a clean URL."

An authorization code is single-use and short-lived, five minutes by Cognito's documentation. Redeem it once and it is gone, so a callback handler that runs twice, or a browser refresh on a URL that still contains ?code=, produces invalid_grant on the second attempt. Retrying the same failed exchange is the wrong test; you need a fresh login and a fresh code. A revoked refresh token gives the same error, and so does one more case people never expect: the app client lacks read access to an attribute the requested scope needs, such as asking for email when the client can read email but not email_verified.

Design the handler to process each result once, then navigate to a clean URL without the code. If the first exchange timed out from the app's point of view, it may still have succeeded on Cognito's side, which is why the retry fails. And keep the PKCE pair together: a fresh code sent with the wrong code_verifier is still not a valid grant, and it is a flow bug, not a callback bug.

The token endpoint has its own redirect rule

Here is the split that matters most after the browser comes back successfully. At authorize, the callback must be registered. At the token exchange, the redirect_uri must be the same value that was used at authorize. Suppose both https://app.example.com/callback and https://app.example.com/callback/ are registered and the login used the first; sending the second in the token request fails, with unauthorized_client and invalid_redirect, even though it is on the list.

At authorizeAt the token exchangeResult
Registered callback ASame callback AFine; other checks still apply
Registered callback ARegistered callback Bunauthorized_client, invalid_redirect
Valid callback and clientA code already usedinvalid_grant
Correct code and callbackWrong secret for a confidential clientinvalid_client

The repair is to carry one canonical redirect value from the authorize request through to the token request, including through any proxy or router that likes to add slashes. Machine-to-machine calls with the client_credentials grant never use a browser code or a redirect at all, so if that is the grant in your POST body, a redirect investigation is the wrong page entirely.

invalid_scope: unknown, malformed, or not allowed

Scopes travel in the authorize request as a space-separated, URL-encoded list: scope=openid%20email%20profile. The standard ones are openid, email, phone, profile and aws.cognito.signin.user.admin; a custom scope from a resource server looks like https://api.example.com/orders.read, identifier and name together. The app client has to allow every scope the app asks for.

The endpoint decides the error. At authorize, an unknown or malformed scope comes back as invalid_scope on your callback. At the token endpoint, Cognito refuses the whole request rather than quietly dropping the bad scope: a scope that names a resource server that does not exist is invalid_scope, while a scope that exists but is not allowed for this client is invalid_grant. That difference is exactly why the first thing to record is which endpoint answered.

If your configured scope carries a resource-server prefix, orders.read on its own will not match it. Removing openid silences the error and takes the ID token with it, which the application still expects. And offline_access does nothing in Cognito: the code grant returns a refresh token whenever the client is configured to, and asking for the scope neither adds nor removes one.

Google, SAML and friends: two hops, two callbacks

With a social or corporate provider, the login is four redirects, not two. Your app sends the browser to Cognito. Cognito sends it to the provider. The provider sends it back to Cognito. Cognito sends it to your callback. A failure at any hop looks like "login redirects are broken", and the fix lives with whichever hop the browser was on when it failed.

Read the address bar at the moment of failure. On a Cognito domain with your client ID and redirect_uri in the request, start with the app client's callback list. If the identity provider itself shows an error about an invalid reply URL or redirect URI, the problem is the provider's registration of Cognito's return address, which for SAML is the pool's /saml2/idpresponse path, not your app and not an ALB's /oauth2/idpresponse. Swapping those two paths breaks the hop that was working. When several teams own several hops, a four-line diagram of who redirects to whom saves a week of editing configuration that was already right.

When the callback is fixed and the login still fails

Once the registered redirect is right, the login page opens, the user signs in, and the app can still fall over on the next step: the code exchange, state validation, scopes, cookies, or its own routing. That does not mean the callback fix was wrong. It means you have moved one step forward, and each of these has its own small cause.

A blank page after login is usually the app: the callback route does not exist in the deployed build, or the host does not serve client-side routes, and no Cognito setting can make a server serve a path it does not have. A login that loops straight back to the login page is a session that was never stored or never recognized, often from mixing an older auth library with a newer API on the same path. A sign-out that lands somewhere odd is a logout request with the wrong parameter for the list you edited. And a successful login with no ID token is a scope problem; the ALB needs openid, and so does any app that expects to know who signed in.

Jake's second bug was the double exchange. The fixed login worked, the dashboard loaded, and a refresh threw invalid_grant because the callback page re-ran its handler with the stale code still in the address bar. Ethan did not add another callback. He made the handler navigate away after the first exchange, which is what the error had been asking for all along.

A worked example: ten minutes, two environments, one wrong client

Here is Jake's afternoon in the shape you can reuse. The booking dashboard has a production callback, https://booking.example.com/auth/callback, registered on the production client and nothing else. Development runs on http://localhost:5173/auth/callback, registered on a separate development client. On the new laptop, the fresh checkout came with a production environment file, so the local build started with client_id=PRODUCTIONCLIENT and sent a localhost redirect that the production client had never seen. Cognito answered redirect_mismatch, and it was right to.

The wrong fix was obvious and tempting: add the localhost URL to the production client and move on. It would have worked. It would also have taught the production login to trust a developer's laptop forever. The right fix took the same ten minutes and left production untouched.

MinutesStepWhat Jake wrote down
0 to 2Capture the authorize requestclient_id=PRODUCTIONCLIENT, redirect_uri=http://localhost:5173/auth/callback
2 to 4Describe that clientOne callback, the production HTTPS one
4 to 6CompareWrong client for this environment, not a missing URL
6 to 8Fix the owning configurationLocal environment file points at the development client
8 to 10Fresh loginLogin page opens; next error, if any, is a new clue

Those are planning minutes, not a promise about how fast any console change propagates. The useful habit is that each step answers one question and writes one thing down, so when the next error arrived, the invalid_grant on refresh, nobody went back and widened the callback list. The cost of this bug was never an AWS charge; there is no honest dollar figure to put on an OAuth mismatch, so this page does not invent one. The cost was staff who could not open the dashboard, and that is the number to keep in mind when choosing between a two-minute wrong fix and a ten-minute right one.

PKCE, public clients and why a browser app should have no secret

A quick word on the design behind several of the errors above, because it decides which client you should have made in the first place. A browser or mobile app cannot keep a secret; anything shipped to the user can be read by the user. So Cognito, like every OAuth server, offers the authorization code grant with PKCE for public clients. The app invents a random code_verifier, sends its hash as code_challenge with the authorize request (Cognito accepts only the S256 method), and later proves it holds the original verifier when it exchanges the code. A stolen code is useless without the verifier, and no secret ever leaves the server.

That is why a confidential client with a generated secret belongs to a backend, and a public client without one belongs to a browser. Mix them up and you get either a secret in a JavaScript bundle or a browser trying to authenticate as something it cannot be, and both end at the token endpoint as invalid_client. Cognito's token endpoint also sends an Access-Control-Allow-Origin: * header, so a public browser client can complete the exchange cross-origin on its own; you do not need a proxy just to call it. If you are starting a new app and the choice is in front of you, choose the public client with PKCE for anything that runs in a browser, and keep the secret-bearing client for the server that can actually protect it.

The order to work in, especially in production

Production OAuth settings are a security boundary. Widening the callback list to match every failed request is how an app ends up trusting destinations nobody meant to trust. So observe first, change least.

  1. Write down the exact error and the endpoint it came from.
  2. For a redirect failure, capture client_id and the decoded redirect_uri from the Network panel.
  3. Describe that exact app client: callbacks, sign-out URLs, flows, scopes, identity providers.
  4. Compare scheme, host, port, path, case and trailing slash. Fix the app, or register the legitimate URL, in the configuration that survives deployment.
  5. For an ALB, use the lowercase https://HOST/oauth2/idpresponse on the listener's client.
  6. Start a fresh login. Never reuse an old code to test the token step.
  7. If the next error is invalid_client, invalid_grant or invalid_scope, follow its own section rather than undoing the callback fix.

Keep a copy of the client's previous settings and note what you changed. A disappearing error page is not an acceptance test; the app has to complete the login and use the session. Before promoting a build, run a real login in a real browser against the target environment, check that the authorize request carries the expected client and redirect, exchange the result once, land on an authenticated route, then sign out and confirm the separate sign-out destination. A green health check says the server serves files; it says nothing about OAuth.

For teams with several apps, a short inventory of pool, Region, client, client type, callbacks, sign-out URLs, domain and who owns the config, kept as configuration rather than secrets, turns the next incident into a lookup. And when a proxy, CDN or hosting change touches the public hostname, put OAuth on the release checklist, because that is the change that looks harmless to the deployment team and blocks every login the next morning.

What to send if you have to escalate

Send a small, accurate set, not a recording of retries: the timestamp and Region, the user pool and app client IDs, the Cognito domain, the failing endpoint and method, the error and its description, and a redacted authorize URL showing the decoded callback. For an ALB, add the public hostname, the listener's authentication settings and the required callback path. For a token problem, say the grant type, whether the client is public or confidential, whether the code was fresh, whether PKCE was used, and whether the token request's redirect matched the authorize request. Leave out client secrets, access tokens, refresh tokens, authorization codes, and any intact network trace that contains them.

Then say what changed between the last working deploy and the first failure: front-end origin, callback route, proxy, app client, Amplify outputs, provider integration, listener. Two real requests side by side, old build and new, move a ticket faster than any description. And remember what nobody can do for you: an external provider's registration is the provider's to fix, a redirect to a domain you do not control should never be registered to silence an error, and an app that spends a code twice has to be fixed by whoever owns the app.

Cognito redirect and OAuth questions, answered short

How do I fix AWS Cognito redirect mismatch?

Read the decoded redirect_uri and client_id from the browser's /oauth2/authorize request, then make that exact string one of the Allowed callback URLs on that app client, or change the app to send a URL that is already registered. Fresh login afterwards.

Why does Cognito redirect_mismatch happen on localhost?

The port, path, host form or trailing slash differs from what is registered. Register the real development callback with its real port on the development client; http://localhost, http://127.0.0.1 and http://[::1] are all allowed with custom ports.

Does a trailing slash matter in Cognito callback URLs?

Yes. The slash is part of the string Cognito compares. Keep the app's redirect and the registered callback identical, down to the last character.

Can a Cognito callback URL use HTTP instead of HTTPS?

Only for localhost and the loopback addresses, for testing. Every other callback must be HTTPS, or an app scheme such as myapp://example.

Where do I find redirect_uri in Chrome Developer Tools?

Open Network, turn on Preserve log, click login, select the /oauth2/authorize request, and read the decoded redirect_uri in its query parameters.

Are Cognito callback URLs and sign-out URLs the same list?

No. Callback URLs authorize where users go after sign-in. Sign-out URLs authorize logout_uri destinations after sign-out. A URL in the wrong list does nothing for the other flow.

How do I fix redirect mismatch with AWS Amplify?

Compare redirectSignIn in your Amplify configuration with the redirect_uri the browser actually sends and the app client's callbacks. Fix the configuration that survives deployment, redeploy, and read the new request.

How do I fix AWS ALB Cognito redirect_mismatch?

Register the public HTTPS hostname users visit, followed by /oauth2/idpresponse, in lowercase, as a callback on the exact app client the listener uses. The client also needs a secret, the code grant and the openid scope.

Why does Cognito return invalid_client?

Client authentication at the token endpoint failed: wrong client ID, wrong or missing secret, or a secret for another client or pool. Keep secrets on a backend, never in browser code.

Why does Cognito return invalid_grant after login?

The authorization code was already used or does not exist, a refresh token was revoked, or the client cannot read an attribute that a requested scope needs. Process each code once and start a fresh login to test.

Can an authorization code be reused in Cognito?

No. A code is single-use and expires after five minutes. A page refresh that re-sends the same code gets invalid_grant.

Why does Cognito return invalid_scope?

The request names a scope that is unknown or malformed, or a resource server that does not exist. At the token endpoint, a scope that exists but is not allowed for the client returns invalid_grant instead.

What does invalid_redirect mean on the token endpoint?

The redirect_uri in the token request differs from the one used at authorize. Cognito returns unauthorized_client with an invalid_redirect description. Send the same string at both steps.

Why is Cognito still not working after I fixed the redirect?

You have reached the next step. Client authentication, PKCE, scopes, attribute permissions, a code redeemed twice, or the app's own callback route can each fail after a correct redirect, and each has its own fix.

Does Cognito managed login use different callback rules from the hosted UI?

No. Managed login and the classic hosted UI share the authorize, token and logout endpoints and the same app client callback list. Debug the request, not the branding.

Why is Cognito not working after I changed my domain?

A new public hostname is a new callback string. Register the new one on the app client and, behind a load balancer, the new https://host/oauth2/idpresponse value.

What are the Cognito OAuth error codes?

At /oauth2/authorize: redirect_mismatch, invalid_request, unauthorized_client, invalid_scope and server_error. At /oauth2/token: invalid_request, invalid_client, invalid_grant, unauthorized_client and unsupported_grant_type. The endpoint tells you which step to fix.

For readers preparing for an AWS certification

We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.

Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • Security – Specialty (SCS-C03).

Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:

1. What causes the Cognito redirect_mismatch error?

The redirect_uri in the sign-in request does not exactly match one of the app client's allowed callback URLs, including scheme, path and trailing slash.

2. Can callback URLs use plain HTTP?

Only for localhost during development. Other callback URLs must use HTTPS.

3. Which OAuth flow should a single-page app use?

The authorization code flow with PKCE. The implicit flow is no longer recommended.

4. Where is the sign-out URL configured?

In the app client's allowed sign-out URLs; the logout_uri parameter must match one of them.

5. Why might sign-in work on the production domain but fail on a preview URL?

The preview domain is not listed in the allowed callback URLs.

6. Should a browser app use a client secret?

No. Public clients such as SPAs and mobile apps use app clients without a secret, protected by PKCE.

Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.

If a login page is blocking real users right now, the browser's own authorize request is the fastest honest evidence you have. Read it, match it against the one client it names, and change the smallest thing that makes the two agree. Jake's dashboard signs people in again, the production client never learned about his laptop, and the refresh bug that followed was fixed in the handler, not in Cognito. Every error after a correct redirect is a step forward with its own short answer, and none of them is a reason to widen a list you worked hard to keep exact.

📌 If you keep one line from this page

Fix redirect_mismatch by matching the browser's actual redirect_uri to the exact callback registered on the app client that request names.

Read the request first. The config file only tells you what you meant.

Revision note. Written October 8, 2026, with managed login and the classic hosted UI sharing the same OAuth endpoints. If a login page is blocking real users right now, the browser's own authorize request is the fastest honest evidence you have.

Related