Repository navigation
Reuse login redirect_uri in token request - #15
Conversation
The token request dropped the query string from redirect_uri, so it didn't match the one used for registration and authorization, and the IdP rejected the code exchange with invalid_grant. Store the exact redirect_uri at login and send it back unchanged.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The fix is minimal, matches the issue's proposed solution exactly, and the stored redirect URI is correctly set, reused with a consistent fallback, and cleared.
Review effort: Balanced
Findings: None
What changed in this PR
This PR fixes a login failure (400 invalid_grant) that occurred whenever an app signed in from a URL containing a query string. Per RFC 6749 §4.1.3, the redirect_uri in the token request must exactly match the one used in the authorization request. Previously login() authorized with origin + pathname + search while handleRedirectFromLogin() exchanged the code using only origin + pathname, causing a mismatch. The fix persists the exact redirect URI during login() and reuses it during the token exchange.
Changes:
login()now saves the exactsanitizedRedirecttosessionStorageassolid_oidc_redirect_uri.- The token request reuses the stored URI, falling back to
origin + pathname + search(aftercode/iss/stateare stripped). - The new session key is cleared alongside the other
solid_oidc_*keys after token exchange.
| File | Description |
|---|---|
| solid-oidc.js | Stores the authorization redirect_uri in sessionStorage and reuses it in the token request so both requests match, with a cleanup removal added. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fixes #14.
login()registers the client and starts authorization withorigin + pathname + search, buthandleRedirectFromLogin()sentorigin + pathnameto the token endpoint. When the app URL has a query string (e.g.?tracker=…), the two don't match and the IdP returns400 invalid_grant(RFC 6749 §4.1.3).Changes:
login()saves the exact redirect URI tosessionStorageassolid_oidc_redirect_uriorigin + pathname + search(aftercode/iss/stateare stripped)solid_oidc_*keys