Compare commits

...

2 Commits

Author SHA1 Message Date
19fda6aa64 feat(authn-oidc): allow overwriting of cookie name
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
2024-06-05 16:13:45 +02:00
65238f1ff3 feat(authn-oidc): include proxy in cookie name
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
2024-06-05 16:00:23 +02:00
2 changed files with 11 additions and 7 deletions

View File

@ -42,7 +42,7 @@ func (a *Authenticator) PreAuthentication(w http.ResponseWriter, r *http.Request
return errors.WithStack(err) return errors.WithStack(err)
} }
sess, err := a.store.Get(r, a.getCookieName(options.Cookie.Name, layer.Name)) sess, err := a.store.Get(r, a.getCookieName(options.Cookie.Name, layer.Proxy, layer.Name))
if err != nil { if err != nil {
logger.Error(ctx, "could not retrieve session", logger.E(errors.WithStack(err))) logger.Error(ctx, "could not retrieve session", logger.E(errors.WithStack(err)))
} }
@ -121,7 +121,7 @@ func (a *Authenticator) Authenticate(w http.ResponseWriter, r *http.Request, lay
return nil, errors.WithStack(err) return nil, errors.WithStack(err)
} }
sess, err := a.store.Get(r, a.getCookieName(options.Cookie.Name, layer.Name)) sess, err := a.store.Get(r, a.getCookieName(options.Cookie.Name, layer.Proxy, layer.Name))
if err != nil { if err != nil {
return nil, errors.WithStack(err) return nil, errors.WithStack(err)
} }
@ -401,8 +401,14 @@ func (a *Authenticator) getClient(options *LayerOptions, redirectURL string) (*C
return client, nil return client, nil
} }
func (a *Authenticator) getCookieName(cookieName string, layerName store.LayerName) string { const defaultCookieNamePrefix = "_bouncer_authn_oidc"
return fmt.Sprintf("%s_%s", cookieName, layerName)
func (a *Authenticator) getCookieName(cookieName string, proxyName store.ProxyName, layerName store.LayerName) string {
if cookieName != "" {
return cookieName
}
return strings.ToLower(fmt.Sprintf("%s_%s_%s", defaultCookieNamePrefix, proxyName, layerName))
} }
var ( var (

View File

@ -8,8 +8,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const defaultCookieName = "_bouncer_authn_oidc"
type LayerOptions struct { type LayerOptions struct {
authn.LayerOptions authn.LayerOptions
OIDC OIDCOptions `mapstructure:"oidc"` OIDC OIDCOptions `mapstructure:"oidc"`
@ -57,7 +55,7 @@ func fromStoreOptions(storeOptions store.LayerOptions) (*LayerOptions, error) {
Scopes: []string{"openid"}, Scopes: []string{"openid"},
}, },
Cookie: CookieOptions{ Cookie: CookieOptions{
Name: defaultCookieName, Name: "",
Path: "/", Path: "/",
HTTPOnly: true, HTTPOnly: true,
MaxAge: time.Hour, MaxAge: time.Hour,