From dcedb09d9651471bb46601c11d2192f2a202ffee Mon Sep 17 00:00:00 2001 From: Ian Spence Date: Fri, 15 Mar 2024 19:08:02 -0400 Subject: [PATCH] Send extra parameters with client credentials request (#354) Co-authored-by: Ewan Harris --- README.md | 2 +- authentication/oauth.go | 4 ++ authentication/oauth_test.go | 20 ++++++++ go.mod | 2 +- ...Should_allow_sending_extra_parameters.yaml | 46 +++++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 test/data/recordings/authentication/TestLoginWithClientCredentials/Should_allow_sending_extra_parameters.yaml diff --git a/README.md b/README.md index 6ace1825..8d0d4da8 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This library follows the [same support policy as Go](https://go.dev/doc/devel/release#policy). The last two major Go releases are actively supported and compatibility issues will be fixed. While you may find that older versions of Go may work, we will not actively test and fix compatibility issues with these versions. -- Go 1.20+ +- Go 1.21+ ### Installation diff --git a/authentication/oauth.go b/authentication/oauth.go index 236a43ee..7686ec3d 100644 --- a/authentication/oauth.go +++ b/authentication/oauth.go @@ -148,6 +148,10 @@ func (o *OAuth) LoginWithClientCredentials(ctx context.Context, body oauth.Login data.Set("organization", body.Organization) } + for k, v := range body.ExtraParameters { + data.Set(k, v) + } + err = o.authentication.addClientAuthenticationToURLValues(body.ClientAuthentication, data, true) if err != nil { diff --git a/authentication/oauth_test.go b/authentication/oauth_test.go index 69c638d3..5fc996fb 100644 --- a/authentication/oauth_test.go +++ b/authentication/oauth_test.go @@ -207,6 +207,26 @@ func TestLoginWithClientCredentials(t *testing.T) { assert.Equal(t, "Bearer", tokenSet.TokenType) }) + t.Run("Should allow sending extra parameters", func(t *testing.T) { + skipE2E(t) + configureHTTPTestRecordings(t, authAPI) + + tokenSet, err := authAPI.OAuth.LoginWithClientCredentials(context.Background(), oauth.LoginWithClientCredentialsRequest{ + ClientAuthentication: oauth.ClientAuthentication{ + ClientSecret: clientSecret, + ClientID: "test-other-clientid", + }, + Audience: "test-audience", + ExtraParameters: map[string]string{ + "test": "value", + }, + }, oauth.IDTokenValidationOptions{}) + + assert.NoError(t, err) + assert.NotEmpty(t, tokenSet.AccessToken) + assert.Equal(t, "Bearer", tokenSet.TokenType) + }) + t.Run("Should support using private key jwt auth", func(t *testing.T) { skipE2E(t) diff --git a/go.mod b/go.mod index 5d8a6b1b..8dac9859 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/auth0/go-auth0 -go 1.20 +go 1.21 require ( github.com/PuerkitoBio/rehttp v1.3.0 diff --git a/test/data/recordings/authentication/TestLoginWithClientCredentials/Should_allow_sending_extra_parameters.yaml b/test/data/recordings/authentication/TestLoginWithClientCredentials/Should_allow_sending_extra_parameters.yaml new file mode 100644 index 00000000..9a32ddaa --- /dev/null +++ b/test/data/recordings/authentication/TestLoginWithClientCredentials/Should_allow_sending_extra_parameters.yaml @@ -0,0 +1,46 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 170 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: audience=test-audience&client_id=test-other-clientid&client_secret=test-client_secret&grant_type=client_credentials&test=value + form: + client_id: + - test-other-clientid + client_secret: + - test-client_secret + audience: + - test-audience + grant_type: + - client_credentials + test: + - value + headers: + Content-Type: + - application/x-www-form-urlencoded + url: https://go-auth0-dev.eu.auth0.com/oauth/token + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"access_token":"test-other-access-token","expires_in":86400,"token_type":"Bearer"}' + headers: + Content-Type: + - application/json + status: 200 OK + code: 200 + duration: 145.095875ms