pomerium/internal/identity/oidc/config.go
Caleb Doxsey 5e3aa91f23
authenticate: delay evaluation of OIDC provider (#1802)
* authenticate: delay evaluation of OIDC provider

* add additional error message

* address comments
2021-01-26 09:20:56 -07:00

44 lines
1 KiB
Go

package oidc
import (
"github.com/coreos/go-oidc/v3/oidc"
"golang.org/x/oauth2"
)
type config struct {
getProvider func() (*oidc.Provider, error)
getVerifier func(provider *oidc.Provider) *oidc.IDTokenVerifier
getOauthConfig func(provider *oidc.Provider) *oauth2.Config
}
// An Option customizes the config.
type Option func(*config)
func getConfig(options ...Option) *config {
cfg := &config{}
for _, option := range options {
option(cfg)
}
return cfg
}
// WithGetOauthConfig sets the getOauthConfig function in the config.
func WithGetOauthConfig(f func(provider *oidc.Provider) *oauth2.Config) Option {
return func(cfg *config) {
cfg.getOauthConfig = f
}
}
// WithGetProvider sets the getProvider function in the config.
func WithGetProvider(f func() (*oidc.Provider, error)) Option {
return func(cfg *config) {
cfg.getProvider = f
}
}
// WithGetVerifier sets the getVerifier function in the config.
func WithGetVerifier(f func(*oidc.Provider) *oidc.IDTokenVerifier) Option {
return func(cfg *config) {
cfg.getVerifier = f
}
}