feat(common.oauth): Add audience parameter (#12821)
This commit is contained in:
parent
bea5414384
commit
1eb70808d0
|
|
@ -13,20 +13,28 @@ type OAuth2Config struct {
|
|||
ClientID string `toml:"client_id"`
|
||||
ClientSecret string `toml:"client_secret"`
|
||||
TokenURL string `toml:"token_url"`
|
||||
Audience string `toml:"audience"`
|
||||
Scopes []string `toml:"scopes"`
|
||||
}
|
||||
|
||||
func (o *OAuth2Config) CreateOauth2Client(ctx context.Context, client *http.Client) *http.Client {
|
||||
if o.ClientID != "" && o.ClientSecret != "" && o.TokenURL != "" {
|
||||
oauthConfig := clientcredentials.Config{
|
||||
ClientID: o.ClientID,
|
||||
ClientSecret: o.ClientSecret,
|
||||
TokenURL: o.TokenURL,
|
||||
Scopes: o.Scopes,
|
||||
}
|
||||
ctx = context.WithValue(ctx, oauth2.HTTPClient, client)
|
||||
client = oauthConfig.Client(ctx)
|
||||
if o.ClientID == "" || o.ClientSecret == "" || o.TokenURL == "" {
|
||||
return client
|
||||
}
|
||||
|
||||
oauthConfig := clientcredentials.Config{
|
||||
ClientID: o.ClientID,
|
||||
ClientSecret: o.ClientSecret,
|
||||
TokenURL: o.TokenURL,
|
||||
Scopes: o.Scopes,
|
||||
}
|
||||
|
||||
if o.Audience != "" {
|
||||
oauthConfig.EndpointParams.Add("audience", o.Audience)
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, oauth2.HTTPClient, client)
|
||||
client = oauthConfig.Client(ctx)
|
||||
|
||||
return client
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ to use them.
|
|||
# client_id = "clientid"
|
||||
# client_secret = "secret"
|
||||
# token_url = "https://indentityprovider/oauth2/v1/token"
|
||||
# audience = ""
|
||||
# scopes = ["urn:opc:idm:__myscopes__"]
|
||||
|
||||
## Goole API Auth
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
# client_id = "clientid"
|
||||
# client_secret = "secret"
|
||||
# token_url = "https://indentityprovider/oauth2/v1/token"
|
||||
# audience = ""
|
||||
# scopes = ["urn:opc:idm:__myscopes__"]
|
||||
|
||||
## Goole API Auth
|
||||
|
|
|
|||
Loading…
Reference in New Issue