Skip to content

Commit

Permalink
Send extra parameters with client credentials request (#354)
Browse files Browse the repository at this point in the history
Co-authored-by: Ewan Harris <ewan.harris@okta.com>
  • Loading branch information
weirdian2k3 and ewanharris authored Mar 15, 2024
1 parent f0a5a2a commit dcedb09
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions authentication/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions authentication/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/auth0/go-auth0

go 1.20
go 1.21

require (
github.com/PuerkitoBio/rehttp v1.3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dcedb09

Please sign in to comment.