OAuth2 redirect_uri mismatch: perché il server rifiuta l’URI di redirect
I server di autorizzazione confrontano redirect_uri inviato con quelli registrati per il client e richiedono una corrispondenza esatta (RFC 6749 sezione 3.1.2.3; RFC 9700 rafforza il requisito). Qualsiasi differenza viene rifiutata, per impedire l’invio del codice di login a un indirizzo's malevolo. Rispondi alle domande o confronta direttamente le due stringhe.
Individua la causa
Confronta i due URI
Tutte le cause e le soluzioni
La richiesta token deve ripetere lo stesso 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.
L’URI è registrato in un solo ambiente
- Each environment (production, staging, local) needs its own URI registered at the authorization server. Register every URI you really use, including
http://localhost:PORT/callbackfor local development where the provider allows it. - Check that the client_id belongs to the same environment as the server you are calling.
L’URI deriva dalla richiesta e viene modificato da un proxy
- 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.
Confronta le stringhe carattere per carattere
- 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.
Wildcard e query string aggiuntive di solito non sono consentite
- 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
stateparameter, not in the redirect URI.
App native, desktop e mobile
- 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.
Controlla i log del provider e la richiesta esatta
- 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.
Domande frequenti
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.
Informazioni sulla pagina
Le risposte non vengono inviate: le domande funzionano nel browser. Se incolli dati negli strumenti collegati, leggi le note sulla privacy e usa dati di test. Consulta l’ privacy notice.
Correlati: diagnostico errori OAuth2 e confronto URI · tester flusso OAuth2 · ricevitore callback · tutte le guide agli errori
Configuriamo e analizziamo OAuth2/OIDC e API gateway, inclusi WSO2 Identity Server e API Manager. Scopri i servizi WSO2 or the revisione di sicurezza.
Scrivici su LinkedIn