fix(common.oauth): Initialize 'EndpointParams' to avoid panic with 'audience' settings (#14331)
This commit is contained in:
parent
062ccb3086
commit
0e591ea8cf
|
|
@ -3,6 +3,7 @@ package oauth
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/clientcredentials"
|
"golang.org/x/oauth2/clientcredentials"
|
||||||
|
|
@ -23,10 +24,11 @@ func (o *OAuth2Config) CreateOauth2Client(ctx context.Context, client *http.Clie
|
||||||
}
|
}
|
||||||
|
|
||||||
oauthConfig := clientcredentials.Config{
|
oauthConfig := clientcredentials.Config{
|
||||||
ClientID: o.ClientID,
|
ClientID: o.ClientID,
|
||||||
ClientSecret: o.ClientSecret,
|
ClientSecret: o.ClientSecret,
|
||||||
TokenURL: o.TokenURL,
|
TokenURL: o.TokenURL,
|
||||||
Scopes: o.Scopes,
|
Scopes: o.Scopes,
|
||||||
|
EndpointParams: make(url.Values),
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.Audience != "" {
|
if o.Audience != "" {
|
||||||
|
|
|
||||||
|
|
@ -499,6 +499,34 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "audience",
|
||||||
|
plugin: &HTTP{
|
||||||
|
URL: u.String() + "/write",
|
||||||
|
HTTPClientConfig: httpconfig.HTTPClientConfig{
|
||||||
|
OAuth2Config: oauth.OAuth2Config{
|
||||||
|
ClientID: "howdy",
|
||||||
|
ClientSecret: "secret",
|
||||||
|
TokenURL: u.String() + "/token",
|
||||||
|
Scopes: []string{"urn:opc:idm:__myscopes__"},
|
||||||
|
Audience: "audience",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tokenHandler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
values := url.Values{}
|
||||||
|
values.Add("access_token", token)
|
||||||
|
values.Add("token_type", "bearer")
|
||||||
|
values.Add("expires_in", "3600")
|
||||||
|
_, err = w.Write([]byte(values.Encode()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
},
|
||||||
|
handler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||||
|
require.Equal(t, []string{"Bearer " + token}, r.Header["Authorization"])
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue