Skip to content

Commit

Permalink
Refactor OIDC scopes to use env-delim
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-smith committed Dec 21, 2023
1 parent a7fd24c commit b8e7534
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ OIDC Provider:
--providers.oidc.issuer-url= Issuer URL [$PROVIDERS_OIDC_ISSUER_URL]
--providers.oidc.client-id= Client ID [$PROVIDERS_OIDC_CLIENT_ID]
--providers.oidc.client-secret= Client Secret [$PROVIDERS_OIDC_CLIENT_SECRET]
--providers.oidc.scopes= Optional additional scopes to request [$PROVIDERS_OIDC_SCOPES]
--providers.oidc.scope= Scopes (default: openid, profile, email) [$PROVIDERS_OIDC_SCOPE]
--providers.oidc.resource= Optional resource indicator [$PROVIDERS_OIDC_RESOURCE]
Generic OAuth2 Provider:
Expand Down
16 changes: 5 additions & 11 deletions internal/provider/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package provider
import (
"context"
"errors"
"strings"

"github.com/coreos/go-oidc"
"golang.org/x/oauth2"
)

// OIDC provider
type OIDC struct {
IssuerURL string `long:"issuer-url" env:"ISSUER_URL" description:"Issuer URL"`
ClientID string `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
AdditionalScopes string `long:"additional-scopes" env:"ADDITIONAL_SCOPES" description:"Additional Scopes"`
IssuerURL string `long:"issuer-url" env:"ISSUER_URL" description:"Issuer URL"`
ClientID string `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
Scopes []string `long:"scope" env:"SCOPE" env-delim:"," default:"openid" default:"profile" default:"email" description:"Scopes"`

OAuthProvider

Expand Down Expand Up @@ -48,14 +47,9 @@ func (o *OIDC) Setup() error {
ClientID: o.ClientID,
ClientSecret: o.ClientSecret,
Endpoint: o.provider.Endpoint(),

// "openid" is a required scope for OpenID Connect flows.
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
Scopes: o.Scopes,
}

additionalScopes := strings.Split(o.AdditionalScopes, ",")
o.Config.Scopes = append(o.Config.Scopes, additionalScopes...)

// Create OIDC verifier
o.verifier = o.provider.Verifier(&oidc.Config{
ClientID: o.ClientID,
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func setupOIDCTest(t *testing.T, bodyValues map[string]map[string]string) (*OIDC

// Setup provider
p := OIDC{
ClientID: "idtest",
ClientSecret: "sectest",
IssuerURL: serverURL.String(),
AdditionalScopes: "groups",
ClientID: "idtest",
ClientSecret: "sectest",
IssuerURL: serverURL.String(),
Scopes: []string{"openid profile email groups"},
}

// Initialise config/verifier
Expand Down

0 comments on commit b8e7534

Please sign in to comment.