Skip to content

Commit

Permalink
Merge pull request #202 from DasSkelett/fix/missing-identity-after-oi…
Browse files Browse the repository at this point in the history
…dc-failure
  • Loading branch information
DasSkelett authored Jun 15, 2022
2 parents 29c783f + 426bc0c commit 36cce5e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/authnz/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,23 @@ func (m *AuthMiddleware) Middleware(next http.Handler) http.Handler {
// functionality i.e. annotate the request context
// with the request user (identity)
if s, err := m.runtime.GetSession(r); err == nil {
if s.Identity == nil {
// Can happen due to an aborted or failed login at the OIDC provider
// Redirect the user to the signin page, so they can redo the login
http.Redirect(w, r, "/signin", http.StatusSeeOther)
return
}
if m.claimsMiddleware != nil {
if err := m.claimsMiddleware(s.Identity); err != nil {
traces.Logger(r.Context()).Error(errors.Wrap(err, "authz middleware failure"))
http.Error(w, "internal server error", http.StatusInternalServerError)
traces.Logger(r.Context()).Error(errors.Wrap(err, "authnz middleware failure"))
http.Redirect(w, r, "/signin", http.StatusSeeOther)
return
}
}
next.ServeHTTP(w, r.WithContext(authsession.SetIdentityCtx(r.Context(), s)))
} else {
// GetSession() errors e.g. after the server restarted, because old session cookies are no longer trusted
// The RequireAuthentication() middleware will be next in line and prompt the user to log in
next.ServeHTTP(w, r)
}
})
Expand Down

0 comments on commit 36cce5e

Please sign in to comment.