Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions pkg/api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ func (s *Server) Wrap(f api.HandlerFunc) http.HandlerFunc {

user, err := s.authenticator.Authenticate(req)
if err != nil {
// Check if this is a FetchUserGroupsError which indicates an auth provider configuration issue
var fetchGroupsErr *gclient.FetchUserGroupsError
if errors.As(err, &fetchGroupsErr) {
http.Error(rw, fmt.Sprintf("Authentication provider configuration error: %s. Please contact an administrator to fix the auth provider configuration.", err.Error()), http.StatusInternalServerError)
return
}

http.Error(rw, err.Error(), http.StatusUnauthorized)

if errors.Is(err, proxy.ErrInvalidSession) {
// The session is invalid, so tell the browser to delete the cookie so that it won't try it again.
http.SetCookie(rw, &http.Cookie{
Expand All @@ -101,7 +92,19 @@ func (s *Server) Wrap(f api.HandlerFunc) http.HandlerFunc {
Path: "/",
MaxAge: -1,
})
// Refresh the page so that the cookie deletes.
http.Redirect(rw, req, req.URL.String(), http.StatusFound)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like an abuse of HTTP but I'm not sure of any other way to delete the cookie and refresh, besides doing this.

return
}

http.Error(rw, err.Error(), http.StatusUnauthorized)

// Check if this is a FetchUserGroupsError which indicates an auth provider configuration issue
var fetchGroupsErr *gclient.FetchUserGroupsError
if errors.As(err, &fetchGroupsErr) {
http.Error(rw, fmt.Sprintf("Authentication provider configuration error: %s. Please contact an administrator to fix the auth provider configuration.", err.Error()), http.StatusInternalServerError)
}

return
}

Expand Down
Loading