Skip to content

Commit 5b7a5e0

Browse files
committed
add extra scopes
1 parent 504be06 commit 5b7a5e0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

internal/provider/oidc.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package provider
33
import (
44
"context"
55
"errors"
6+
"slices"
67

78
"github.com/coreos/go-oidc"
89
"golang.org/x/oauth2"
910
)
1011

1112
// OIDC provider
1213
type OIDC struct {
13-
IssuerURL string `long:"issuer-url" env:"ISSUER_URL" description:"Issuer URL"`
14-
ClientID string `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
15-
ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
14+
IssuerURL string `long:"issuer-url" env:"ISSUER_URL" description:"Issuer URL"`
15+
ClientID string `long:"client-id" env:"CLIENT_ID" description:"Client ID"`
16+
ClientSecret string `long:"client-secret" env:"CLIENT_SECRET" description:"Client Secret" json:"-"`
17+
ExtraScopes []string `long:"extra-scopes" env:"EXTRA_SCOPES" description:"Extra scopes to request. 'openid', 'email' and 'profile' are always included"`
1618

1719
OAuthProvider
1820

@@ -41,14 +43,17 @@ func (o *OIDC) Setup() error {
4143
return err
4244
}
4345

46+
// "openid" is a required scope for OpenID Connect flows.
47+
scopes := append([]string{oidc.ScopeOpenID, "profile", "email"}, o.ExtraScopes...)
48+
slices.Sort(scopes)
49+
4450
// Create oauth2 config
4551
o.Config = &oauth2.Config{
4652
ClientID: o.ClientID,
4753
ClientSecret: o.ClientSecret,
4854
Endpoint: o.provider.Endpoint(),
4955

50-
// "openid" is a required scope for OpenID Connect flows.
51-
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
56+
Scopes: slices.Compact(scopes),
5257
}
5358

5459
// Create OIDC verifier

0 commit comments

Comments
 (0)