Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions proxy/auth/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ func setCookie(w http.ResponseWriter, value TokenData) error {
if err != nil {
return err
}
secure := config.TlsCertPath != ""
cookie := http.Cookie{
Name: common.CookieSessionName,
Value: b64.StdEncoding.EncodeToString(cookieVal),
Secure: config.TlsCertPath != "",
Secure: secure,
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
Path: "/",
Expand Down Expand Up @@ -576,15 +577,24 @@ func clearPKCEVerifierCookie(w http.ResponseWriter, providerName string) {
Path: "/",
Secure: config.TlsCertPath != "",
HttpOnly: true,
SameSite: http.SameSiteLaxMode, // Use Lax to match the set cookie
SameSite: http.SameSiteLaxMode,
}
http.SetCookie(w, &cookie)
}

// clearSessionCookie removes the session cookie
func clearSessionCookie(w http.ResponseWriter, r *http.Request) {
// TODO EDM-2612 Setting cookie here was not working, removed the code - needs to be investigated.
// Set Clear-Site-Data header to instruct browser to clear cookies
cookie := http.Cookie{
Name: common.CookieSessionName,
Value: "",
MaxAge: -1,
Path: "/",
Secure: config.TlsCertPath != "",
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
}
http.SetCookie(w, &cookie)

w.Header().Set("Clear-Site-Data", `"cookies"`)
}

Expand Down
45 changes: 1 addition & 44 deletions proxy/auth/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package auth

import (
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -143,48 +141,7 @@ func (o *OpenShiftAuthHandler) RefreshToken(refreshToken string) (TokenData, *in
}

func (o *OpenShiftAuthHandler) Logout(token string) (string, error) {
// OpenShift OAuth logout endpoint is typically at {issuer}/logout
// Try to discover it from the OAuth discovery endpoint
discoveryURL := fmt.Sprintf("%s/.well-known/oauth-authorization-server", o.apiServerURL)
req, err := http.NewRequest(http.MethodGet, discoveryURL, nil)
if err != nil {
return "", nil
}

httpClient := http.Client{
Transport: &http.Transport{
TLSClientConfig: o.tlsConfig,
},
}

res, err := httpClient.Do(req)
if err != nil {
return "", nil
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return "", nil
}

bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return "", nil
}

var discovery openshiftOAuthDiscovery
if err := json.Unmarshal(bodyBytes, &discovery); err != nil {
return "", nil
}

if discovery.Issuer != "" {
logoutURL, err := url.Parse(discovery.Issuer)
if err == nil {
logoutURL.Path = "/logout"
return logoutURL.String(), nil
}
}

// The cookie will be cleared by the proxy
return "", nil
}

Expand Down