You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-08-08 22:46:33 +02:00
Session aware logout, backend logout url approach (#1876)
* Session aware logout, backend logout url approach * Add CHANGELOG.md and documentation for #1876 * Proper http handling and case change for golint compliance * Update alpha_config.md * Fix case conformity * Change placeholder from ${id_token} to {id_token} As this should be specified in a URL and curly braces should be escaped as %7b and %7d, therefore using {} shouldn't be an issue * Apply suggestions from code review Co-authored-by: Jan Larwig <jan@larwig.com> * Add other suggestions * Add suggestions and move background logout to generic provider * Changelog updated * Update oauthproxy.go Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> * Add comment for gosec, remove sensitive data from log --------- Co-authored-by: Jan Larwig <jan@larwig.com> Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
This commit is contained in:
@ -334,15 +334,15 @@ func (p *OAuthProxy) buildProxySubrouter(s *mux.Router) {
|
||||
s.Use(prepareNoCacheMiddleware)
|
||||
|
||||
s.Path(signInPath).HandlerFunc(p.SignIn)
|
||||
s.Path(signOutPath).HandlerFunc(p.SignOut)
|
||||
s.Path(oauthStartPath).HandlerFunc(p.OAuthStart)
|
||||
s.Path(oauthCallbackPath).HandlerFunc(p.OAuthCallback)
|
||||
|
||||
// Static file paths
|
||||
s.PathPrefix(staticPathPrefix).Handler(http.StripPrefix(p.ProxyPrefix, http.FileServer(http.FS(staticFiles))))
|
||||
|
||||
// The userinfo endpoint needs to load sessions before handling the request
|
||||
// The userinfo and logout endpoints needs to load sessions before handling the request
|
||||
s.Path(userInfoPath).Handler(p.sessionChain.ThenFunc(p.UserInfo))
|
||||
s.Path(signOutPath).Handler(p.sessionChain.ThenFunc(p.SignOut))
|
||||
}
|
||||
|
||||
// buildPreAuthChain constructs a chain that should process every request before
|
||||
@ -746,9 +746,43 @@ func (p *OAuthProxy) SignOut(rw http.ResponseWriter, req *http.Request) {
|
||||
p.ErrorPage(rw, req, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
p.backendLogout(rw, req)
|
||||
|
||||
http.Redirect(rw, req, redirect, http.StatusFound)
|
||||
}
|
||||
|
||||
func (p *OAuthProxy) backendLogout(rw http.ResponseWriter, req *http.Request) {
|
||||
session, err := p.getAuthenticatedSession(rw, req)
|
||||
if err != nil {
|
||||
logger.Errorf("error getting authenticated session during backend logout: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if session == nil {
|
||||
return
|
||||
}
|
||||
|
||||
providerData := p.provider.Data()
|
||||
if providerData.BackendLogoutURL == "" {
|
||||
return
|
||||
}
|
||||
|
||||
backendLogoutURL := strings.ReplaceAll(providerData.BackendLogoutURL, "{id_token}", session.IDToken)
|
||||
// security exception because URL is dynamic ({id_token} replacement) but
|
||||
// base is not end-user provided but comes from configuration somewhat secure
|
||||
resp, err := http.Get(backendLogoutURL) // #nosec G107
|
||||
if err != nil {
|
||||
logger.Errorf("error while calling backend logout: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
logger.Errorf("error while calling backend logout url, returned error code %v", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// OAuthStart starts the OAuth2 authentication flow
|
||||
func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
|
||||
// start the flow permitting login URL query parameters to be overridden from the request URL
|
||||
|
Reference in New Issue
Block a user