- Notifications
You must be signed in to change notification settings - Fork905
fix: redirect to login page on OIDC expiry instead of showing raw JSON#18271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Fixes#18201When OIDC sessions expire or authentication fails, users now get redirectedto the login page with a user-friendly error message instead of seeing rawJSON error responses.Changes:- Modified OAuth2 middleware to redirect to /login?message=<error> for OIDC failures- Added user-friendly error messages for different failure scenarios: - Session expired errors for missing/mismatched cookies - Authentication failed messages for OIDC provider errors - Proper URL encoding of error messages- Preserved device flow behavior (still returns JSON as expected)- Updated tests to verify redirect behavior- Added comprehensive test coverage for new redirect functionalityThis significantly improves the user experience when OIDC authenticationfails, especially for session expiry scenarios.
I have read the CLA Document and I hereby sign the CLA Coder Assistant seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, pleaseadd the email address used for this commit to your account. |
Fixes#18201
Problem
When OIDC sessions expire or authentication fails, users see ugly raw JSON error responses instead of being redirected to a user-friendly login page with clear error messages.
Before:
After:
Users are redirected to
/login?message=Authentication+failed%3A+Session+expired%2C+please+sign+in+again
Solution
Modified the OAuth2 middleware (
coderd/httpmw/oauth2.go
) to redirect to the login page instead of returning JSON errors for OIDC authentication failures.Changes Made
authorization_pending
as expected by OAuth device flow clientsError Message Examples
Authentication failed: Session expired, please sign in again
(for expired sessions)Authentication failed: invalid_request - The request is missing a required parameter
(for OIDC provider errors)Authentication failed: Invalid authentication state
(for missing state)Testing
OIDCErrorRedirectsToLogin
: Tests OIDC provider error parametersNoStateRedirectsToLogin
: Tests missing state parameterNoStateCookieRedirectsToLogin
: Tests missing session cookieMismatchedStateRedirectsToLogin
: Tests state mismatch scenariosImpact
This significantly improves the user experience when OIDC authentication fails, especially for session expiry scenarios. Users now get a proper login page with clear instructions instead of confusing JSON errors.