React SPA sign-in fails with AADSTS9002326 despite registered redirect URI; misleading error guidance
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- azure, react, typescript
- Área
- authentication, frontend, tooling
Línea de trabajo
Empieza por create-app.ts, spa-redirect-advisory.ts y project_hydrate_config; después inspecciona auth-error-guidance.ts, samples/react-spa-functions/src/App.tsx y la nota de inicio de sesión de run-local. Sigue la reparación de la redirección de la aplicación reutilizada y el aviso sobre VITE_CLIENT_ID/VITE_TENANT_ID. Se considera terminado cuando los fallos se muestran sin bloquear, la hidratación explica cómo verificar la aplicación objetivo y todas las indicaciones de inicio de sesión cubren de forma coherente las configuraciones no coincidentes y las reconstrucciones.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
Sign-in in the scaffolded React SPA (react-spa-functions) can fail with
AADSTS9002326 (cross-origin SPA token redemption refused) even when the SPA redirect
URI is already registered on an app registration the user is looking at. The app's own
error guidance then makes this worse: it flatly asserts the failure is a server-side
missing-SPA-redirect-URI problem and "NOT a bug in this app and NOT a stale or
not-reloaded dev server" — which misdirects the user away from the actual most-common root
cause.
Repro (reported)
- Use the MCP server to scaffold the React sample app and run it (
http://localhost:5173). - Click Sign in.
- Sign-in fails. The in-app guidance says to add
http://localhost:5173as a SPA redirect
URI — but it is already on the app registration the user is viewing. - Token request observed at
https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token?...returning the
AADSTS9002326failure.
Root-cause analysis
The error text is over-confident and points only at "add the SPA redirect URI", but the URI
was already present on the registration the user inspected. Ranked real causes:
- Stale / mismatched provisioning state → the running build signs in as a different app
than the one the user edited. The SPA authenticates with theVITE_CLIENT_ID/
VITE_TENANT_IDbaked into its.envat build time. If those were hydrated from stale
or mismatched state (or.envwas edited without a rebuild — Vite bakes env vars in at
build time), the user may have added the redirect URI to a different registration than
the one signing in.project_hydrate_configwrites the values verbatim with no
verification, andfindApplicationByNamereturns the first match, so a duplicate
display name can silently select the wrong app. - Reuse-path self-repair silently swallowed.
project_app_createself-repairs a
reused owning app by addinghttp://localhost:5173to itsspa.redirectUris, but the
call isaddSpaRedirectUris(..., { bestEffort: true })and its result was discarded.
If the signed-in identity lacksApplication.ReadWrite, the add is swallowed and the app
stays unrepaired — with no signal to the user. - Guest / B2B cross-tenant redemption (already advised elsewhere in the server).
Fixes in this change
- Surface the swallowed reuse-path self-repair failure (
create-app.ts+ new
spa-redirect-advisory.ts): capture theaddSpaRedirectUrisresult; when the local SPA
redirect URI can't be confirmed on the reused app, append a non-blocking,
copy-pasteable warning naming the exact client id + object id and the manualaz rest
PATCH/GET to self-repair. The tool still succeeds. - Add an offline sign-in verification advisory to
project_hydrate_config: append a
persistent "verify this.envtargets the right app" note to the tool output (never to
.env) — confirmVITE_CLIENT_ID/VITE_TENANT_IDmatch the app in the portal Overview
blade, and verify that exact app'sspa.redirectUrisviaaz rest GET; warn when the
tenant id is blank (invalid MSAL authority). - Soften the over-confident auth-error copy (
auth-error-guidance.ts+ its byte-for-byte
twin insamples/react-spa-functions/src/App.tsx+ therun-localsign-in note): reframe
as "almost always an Entra app-registration configuration mismatch", and make the first
remediation "confirm the running build'sVITE_CLIENT_ID/VITE_TENANT_IDmatch the app
you're viewing; rebuild if you changed.env", then keep the SPA-redirect add steps plus
anaz rest GETverification.
Also in this change
- A user-facing bug-report issue template + a lightweight skill/prompt that walks
users through gathering the exact diagnostics needed for sign-in /AADSTS*issues
(.envVITE_*, portal Overview client/tenant id,az restspa.redirectUris, the exact
AADSTS code + request URL).
Notes
The exact sub-cause for the original report can't be determined from the issue alone (needs
the reporter's .env VITE_* values vs. the portal Overview client/tenant id and that app's
spa.redirectUris). The changes above make that mismatch self-evident in tool output and
in the app's own error guidance, instead of misdirecting the user.
- Lenguaje dominante
- TypeScript
- Estrellas
- 14
- Forks
- 5
- Merge medio
- 7 h 18 min
- PR fusionados (30 d)
- 10
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Issues similares
-
category::task code priority::normal
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
e0ipso/strikethroo#145 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
cocos/cocos-docs#3333 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
RevenueCat/react-native-purchases#2079 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
RevenueCat/purchases-hybrid-common#2039 ·
Los mantenedores suelen responder en 1 día
-
agent-reported area/react bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día