diff --git a/oauthproxy.go b/oauthproxy.go index 4eb58e0c..b733a780 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -395,8 +395,11 @@ func buildSessionChain(opts *options.Options, provider providers.Provider, sessi oidcProviderSettings := opts.Providers[0].OIDCConfig if oidcProviderSettings.EnableCookieRefresh { - chain = chain.Append(middleware.NewCookieRefresh(&middleware.CookieRefreshOptions{IssuerURL: oidcProviderSettings.IssuerURL, CookieRefreshName: oidcProviderSettings.CookieRefreshName})) - logger.Printf("Enabling OIDC cookie refresh for the cookie '%s' functionality because OIDCEnableCookieRefresh is enabled", oidcProviderSettings.CookieRefreshName) + if oidcProviderSettings.CookieRefreshURL == "" { + oidcProviderSettings.CookieRefreshURL = fmt.Sprintf("%s/session/refresh", oidcProviderSettings.IssuerURL) + } + chain = chain.Append(middleware.NewCookieRefresh(&middleware.CookieRefreshOptions{CookieRefreshURL: oidcProviderSettings.CookieRefreshURL, CookieRefreshName: oidcProviderSettings.CookieRefreshName})) + logger.Printf("Enabling OIDC cookie refresh functionality for the cookie '%s' using the url '%s' because OIDCEnableCookieRefresh is enabled", oidcProviderSettings.CookieRefreshURL, oidcProviderSettings.CookieRefreshName) } return chain diff --git a/pkg/apis/options/legacy_options.go b/pkg/apis/options/legacy_options.go index c3c010a2..8a53f907 100644 --- a/pkg/apis/options/legacy_options.go +++ b/pkg/apis/options/legacy_options.go @@ -545,6 +545,7 @@ type LegacyProvider struct { OIDCExtraAudiences []string `flag:"oidc-extra-audience" cfg:"oidc_extra_audiences"` OIDCEnableCookieRefresh bool `flag:"oidc-enable-cookie-refresh" cfg:"oidc_enable_cookie_refresh"` OIDCCookieRefreshName string `flag:"oidc-cookie-refresh-name" cfg:"oidc_cookie_refresh_name"` + OIDCCookieRefreshURL string `flag:"oidc-cookie-refresh-url" cfg:"oidc_cookie_refresh_url"` LoginURL string `flag:"login-url" cfg:"login_url"` RedeemURL string `flag:"redeem-url" cfg:"redeem_url"` ProfileURL string `flag:"profile-url" cfg:"profile_url"` @@ -605,6 +606,7 @@ func legacyProviderFlagSet() *pflag.FlagSet { flagSet.StringSlice("oidc-extra-audience", []string{}, "additional audiences allowed to pass audience verification") flagSet.Bool("oidc-enable-cookie-refresh", false, "Refresh the OIDC provider cookies to enable SSO in an extended period of time") flagSet.String("oidc-cookie-refresh-name", "hsdpamcookie", "The name of the cookie that the OIDC provider uses to keep its session fresh") + flagSet.String("oidc-cookie-refresh-url", "", "The URL that is going to be used to refresh the cookie") flagSet.String("login-url", "", "Authentication endpoint") flagSet.String("redeem-url", "", "Token redemption endpoint") flagSet.String("profile-url", "", "Profile access endpoint") diff --git a/pkg/apis/options/providers.go b/pkg/apis/options/providers.go index a7e02b7d..a9e4d3ef 100644 --- a/pkg/apis/options/providers.go +++ b/pkg/apis/options/providers.go @@ -234,6 +234,8 @@ type OIDCOptions struct { EnableCookieRefresh bool `json:"enableCookieRefresh,omitempty"` // Name of the cookie that is going to be extracted from the request and refreshed CookieRefreshName string `json:"cookieRefreshName,omitempty"` + // Url that is going to be used to refresh the cookie + CookieRefreshURL string `json:"cookieRefreshURL,omitempty"` } type LoginGovOptions struct { diff --git a/pkg/middleware/cookie_refresh.go b/pkg/middleware/cookie_refresh.go index a64c161f..06bcfcef 100644 --- a/pkg/middleware/cookie_refresh.go +++ b/pkg/middleware/cookie_refresh.go @@ -11,23 +11,23 @@ import ( ) type CookieRefreshOptions struct { - IssuerURL string CookieRefreshName string + CookieRefreshURL string } func NewCookieRefresh(opts *CookieRefreshOptions) alice.Constructor { cr := &cookieRefresh{ HTTPClient: &http.Client{}, - IssuerURL: opts.IssuerURL, CookieRefreshName: opts.CookieRefreshName, + CookieRefreshURL: opts.CookieRefreshURL, } return cr.refreshCookie } type cookieRefresh struct { HTTPClient *http.Client - IssuerURL string CookieRefreshName string + CookieRefreshURL string } func (cr *cookieRefresh) refreshCookie(next http.Handler) http.Handler { @@ -43,7 +43,7 @@ func (cr *cookieRefresh) refreshCookie(next http.Handler) http.Handler { logger.Errorf("SSO Cookie Refresher - Could find '%s' cookie in the request: %v", cr.CookieRefreshName, err) return } - resp := requests.New(fmt.Sprintf("%s/session/refresh", cr.IssuerURL)). + resp := requests.New(cr.CookieRefreshURL). WithContext(req.Context()). WithMethod("GET"). SetHeader("api-version", "1"). @@ -52,7 +52,7 @@ func (cr *cookieRefresh) refreshCookie(next http.Handler) http.Handler { if resp.StatusCode() != http.StatusNoContent { bodyString := string(resp.Body()) - logger.Errorf("SSO Cookie Refresher - Could not refresh the '%s' cookie due to status and content: %v - %v", cr.CookieRefreshName, resp.StatusCode(), bodyString) + logger.Errorf("SSO Cookie Refresher - Could not refresh the '%s' cookie in the url '%s' due to status and content: %v - %v", cr.CookieRefreshName, cr.CookieRefreshURL, resp.StatusCode(), bodyString) return }