Skip to content

Commit

Permalink
feat: Support OIDC scope parameter (fatedier#3192)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfeury authored Dec 9, 2022
1 parent da51adc commit 649df88
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type OidcClientConfig struct {
// OidcAudience specifies the audience of the token in OIDC authentication
// if AuthenticationMethod == "oidc". By default, this value is "".
OidcAudience string `ini:"oidc_audience" json:"oidc_audience"`
// OidcScope specifies the scope of the token in OIDC authentication
// if AuthenticationMethod == "oidc". By default, this value is "".
OidcScope string `ini:"oidc_scope" json:"oidc_scope"`
// OidcTokenEndpointURL specifies the URL which implements OIDC Token Endpoint.
// It will be used to get an OIDC token if AuthenticationMethod == "oidc".
// By default, this value is "".
Expand All @@ -52,6 +55,7 @@ func getDefaultOidcClientConf() OidcClientConfig {
OidcClientID: "",
OidcClientSecret: "",
OidcAudience: "",
OidcScope: "",
OidcTokenEndpointURL: "",
OidcAdditionalEndpointParams: make(map[string]string),
}
Expand Down Expand Up @@ -99,10 +103,17 @@ func NewOidcAuthSetter(baseCfg BaseConfig, cfg OidcClientConfig) *OidcAuthProvid
eps[k] = []string{v}
}

// Previous versions hardcoded the scope to audience,
// so for backwards compatibility, use that if no scope is set
scope := cfg.OidcAudience
if cfg.OidcScope != "" {
scope = cfg.OidcScope
}

tokenGenerator := &clientcredentials.Config{
ClientID: cfg.OidcClientID,
ClientSecret: cfg.OidcClientSecret,
Scopes: []string{cfg.OidcAudience},
Scopes: []string{scope},
TokenURL: cfg.OidcTokenEndpointURL,
EndpointParams: eps,
}
Expand Down

0 comments on commit 649df88

Please sign in to comment.