Skip to content

Commit

Permalink
feat(common.oauth): Add audience parameter (#12821)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Mar 13, 2023
1 parent bea5414 commit 1eb7080
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
26 changes: 17 additions & 9 deletions plugins/common/oauth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions plugins/outputs/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugins/outputs/http/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1eb7080

Please sign in to comment.