53 lines
896 B
Go
53 lines
896 B
Go
|
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
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|