Adamant Solutions

OAuth2 "redirect_uri mismatch": why the server rejects your redirect URI

Authorization servers compare the redirect_uri you send with the ones registered for your client, and they require an exact match (RFC 6749 section 3.1.2.3; the Security BCP, RFC 9700, tightens this). Any difference, however small, is rejected, so that a login code can never be sent to an attacker's address. Answer the questions to find the difference, or compare the two strings directly.

Find your cause

Compare the two URIs

All the causes and fixes

The token request must repeat the exact redirect_uri

  • If you sent redirect_uri in the authorization request, you must send the identical value in the token request. This often shows up as invalid_grant rather than a redirect error; see OAuth2 invalid_grant.

The URI is registered in one environment only

  • Each environment (production, staging, local) needs its own URI registered at the authorization server. Register every URI you really use, including http://localhost:PORT/callback for local development where the provider allows it.
  • Check that the client_id belongs to the same environment as the server you are calling.

The URI is built from the request: a proxy changes it

  • Behind a reverse proxy or load balancer the application may see http and an internal host name instead of the public https URL, so the generated URI differs from the registered one.
  • Configure the framework to trust the forwarded headers (X-Forwarded-Proto, X-Forwarded-Host) or, better, set the redirect URI explicitly in configuration.

Compare the strings character by character

  • Typical differences: trailing slash, http vs https, a different port, www vs no www, upper vs lower case in the path, localhost vs 127.0.0.1, an extra query string.
  • Paste both into the comparer below: it names every difference.

Wildcards and extra query strings are usually not allowed

  • Modern servers require exact matching and do not accept wildcards (they enable open-redirect attacks). Some allow a variable query string only if registered that way.
  • Put variable data in the OAuth state parameter, not in the redirect URI.

Native, desktop and mobile apps

  • Mobile apps should use claimed https links or the platform's recommended scheme; desktop apps usually use a loopback address such as http://127.0.0.1:PORT/ (RFC 8252). Register exactly what your app uses; for loopback, many servers match any port.
  • Check the provider documentation for the exact rule: it differs.

Look at the provider log and the exact request

  • Copy the full authorization URL from the browser and read the redirect_uri parameter (it is URL-encoded: decode it).
  • Check for invisible characters or a copy/paste from a rich-text document.
  • Make sure you are editing the registration of the same client_id that the request uses.

Frequently asked questions

Why do servers require an exact redirect URI match?

To prevent authorization codes and tokens from being sent to an attacker-controlled address. Loose matching (wildcards, prefixes) has been used in real attacks.

Is a trailing slash really a difference?

Yes. https://app.example.com/cb and https://app.example.com/cb/ are different strings and most servers treat them as different URIs.

Can I register several redirect URIs?

Yes, most servers allow a list. Register each environment's URI separately instead of using wildcards.

About this page

Nothing you select here is sent anywhere: the questions run in your browser. If you paste anything into the related tools, read their privacy notes and use test data. See the privacy notice.

Related: OAuth2 error doctor and URI comparer · OAuth2 flow tester · Callback receiver · All error guides

Still stuck, or designing the flow for your API?

We configure and review OAuth2/OIDC and API gateways, including WSO2 Identity Server and API Manager. See the WSO2 services or the security review.

Message us on LinkedIn