-
Notifications
You must be signed in to change notification settings - Fork 281
/
config.go
44 lines (37 loc) · 1.04 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}
}