edge/pkg/module/auth/middleware/options.go

63 lines
1.5 KiB
Go

package middleware
import (
"net/http"
"time"
)
type GetCookieDomainFunc func(r *http.Request) (string, error)
func defaultGetCookieDomain(r *http.Request) (string, error) {
return "", nil
}
type DefaultUserOptions struct {
GetCookieDomain GetCookieDomainFunc
CookieDuration time.Duration
Tenant string
Entrypoint string
Role string
Issuer string
GetPreferredUsername func(r *http.Request) (string, error)
GetSubject func(r *http.Request) (string, error)
}
type DefaultUserOptionFunc func(opts *DefaultUserOptions)
func defaultUserOptions() *DefaultUserOptions {
return &DefaultUserOptions{
GetCookieDomain: defaultGetCookieDomain,
CookieDuration: 24 * time.Hour,
Tenant: "",
Entrypoint: "",
Role: "",
GetSubject: getAnonymousSubject,
GetPreferredUsername: getAnonymousPreferredUsername,
}
}
func WithCookieOptions(getCookieDomain GetCookieDomainFunc, duration time.Duration) DefaultUserOptionFunc {
return func(opts *DefaultUserOptions) {
opts.GetCookieDomain = getCookieDomain
opts.CookieDuration = duration
}
}
func WithTenant(tenant string) DefaultUserOptionFunc {
return func(opts *DefaultUserOptions) {
opts.Tenant = tenant
}
}
func WithEntrypoint(entrypoint string) DefaultUserOptionFunc {
return func(opts *DefaultUserOptions) {
opts.Entrypoint = entrypoint
}
}
func WithRole(role string) DefaultUserOptionFunc {
return func(opts *DefaultUserOptions) {
opts.Role = role
}
}