goweb-oidc/option.go

59 lines
1000 B
Go
Raw Normal View History

2020-05-20 10:43:12 +02:00
package oidc
import (
"context"
"github.com/coreos/go-oidc"
)
type OptionFunc func(*Option)
type Option struct {
Provider *oidc.Provider
ClientID string
ClientSecret string
RedirectURL string
Scopes []string
}
2020-05-20 13:06:04 +02:00
func WithRedirectURL(url string) OptionFunc {
return func(opt *Option) {
opt.RedirectURL = url
}
}
2020-05-20 10:43:12 +02:00
func WithCredentials(clientID, clientSecret string) OptionFunc {
return func(opt *Option) {
opt.ClientID = clientID
opt.ClientSecret = clientSecret
}
}
func WithScopes(scopes ...string) OptionFunc {
return func(opt *Option) {
opt.Scopes = scopes
}
}
func NewProvider(ctx context.Context, issuer string) (*oidc.Provider, error) {
return oidc.NewProvider(ctx, issuer)
}
func WithProvider(provider *oidc.Provider) OptionFunc {
return func(opt *Option) {
opt.Provider = provider
}
}
func fromDefault(funcs ...OptionFunc) *Option {
opt := &Option{
Scopes: []string{oidc.ScopeOpenID},
}
for _, f := range funcs {
f(opt)
}
return opt
}