Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions pkg/config/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package config

import (
"context"
"fmt"

"github.com/coreos/go-oidc/v3/oidc"
"golang.org/x/oauth2"
Expand All @@ -18,12 +17,24 @@ import (
// OAuth2 holds the configuration for the OAuth2 provider.
type OAuth2 struct {
Issuer string `yaml:"issuer" json:"issuer"`
Endpoint Endpoint `yaml:"endpoint" json:"endpoint"`
ClientID string `yaml:"clientID" json:"clientID"`
ClientSecret string `yaml:"clientSecret" json:"clientSecret"`
Scopes []string `yaml:"scopes" json:"scopes"`
RedirectURL string `yaml:"redirectURL" json:"redirectURL"`
}

type Endpoint struct {
AuthURL string `yaml:"authURL" json:"authURL"`
DeviceAuthURL string `yaml:"deviceAuthURL" json:"deviceAuthURL"`
TokenURL string `yaml:"tokenURL" json:"tokenURL"`

// AuthStyle optionally specifies how the endpoint wants the
// client ID & client secret sent. The zero value means to
// auto-detect.
AuthStyle int `yaml:"authStyle" json:"authStyle"`
}

// GetIssuer returns the OAuth2 issuer.
func (e *OAuth2) GetIssuer() string {
return e.Issuer
Expand Down Expand Up @@ -51,16 +62,23 @@ func (e *OAuth2) GetRedirectURL() string {

// GetOAuth2Config returns an oauth2.Config.
func (e *OAuth2) GetOAuth2Config(c context.Context) (*oauth2.Config, error) {
fmt.Println(e.Scopes)
provider, err := oidc.NewProvider(c, e.Issuer)
if err != nil {
return nil, err
}
return &oauth2.Config{
conf := &oauth2.Config{
ClientID: e.ClientID,
ClientSecret: e.ClientSecret,
Scopes: e.Scopes,
Endpoint: provider.Endpoint(),
RedirectURL: e.RedirectURL,
}, nil
}
if e.Issuer != "" {
provider, err := oidc.NewProvider(c, e.Issuer)
if err != nil {
return nil, err
}
conf.Endpoint = provider.Endpoint()
return conf, nil
}
conf.Endpoint.AuthURL = e.Endpoint.AuthURL
conf.Endpoint.TokenURL = e.Endpoint.TokenURL
conf.Endpoint.AuthStyle = oauth2.AuthStyle(e.Endpoint.AuthStyle)
conf.Endpoint.DeviceAuthURL = e.Endpoint.DeviceAuthURL
return conf, nil
}