Skip to content

Commit e314384

Browse files
committed
fix(client): allow updating when JWKS URI is set (#3935)
1 parent 96d4ffe commit e314384

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

client/sdk_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,20 @@ func TestClientSDK(t *testing.T) {
230230
// secret hashes shouldn't change between these PUT calls
231231
require.Equal(t, result1.ClientSecret, result2.ClientSecret)
232232
})
233+
234+
t.Run("case=patch client that has JSONWebKeysURI", func(t *testing.T) {
235+
op := "replace"
236+
path := "/client_name"
237+
value := "test"
238+
239+
client := createTestClient("")
240+
client.SetJwksUri("https://example.org/.well-known/jwks.json")
241+
created, _, err := c.OAuth2API.CreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
242+
require.NoError(t, err)
243+
client.ClientId = created.ClientId
244+
245+
result, _, err := c.OAuth2API.PatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
246+
require.NoError(t, err)
247+
require.Equal(t, value, pointerx.Deref(result.ClientName))
248+
})
233249
}

client/validator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ func (v *Validator) Validate(ctx context.Context, c *Client) error {
5454
if c.TokenEndpointAuthMethod == "" {
5555
c.TokenEndpointAuthMethod = "client_secret_basic"
5656
} else if c.TokenEndpointAuthMethod == "private_key_jwt" {
57-
if len(c.JSONWebKeysURI) == 0 && c.JSONWebKeys == nil {
57+
if len(c.JSONWebKeysURI) == 0 && c.GetJSONWebKeys() == nil {
5858
return errorsx.WithStack(ErrInvalidClientMetadata.WithHint("When token_endpoint_auth_method is 'private_key_jwt', either jwks or jwks_uri must be set."))
5959
}
6060
if c.TokenEndpointAuthSigningAlgorithm != "" && !isSupportedAuthTokenSigningAlg(c.TokenEndpointAuthSigningAlgorithm) {
6161
return errorsx.WithStack(ErrInvalidClientMetadata.WithHint("Only RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384 and ES512 are supported as algorithms for private key authentication."))
6262
}
6363
}
6464

65-
if len(c.JSONWebKeysURI) > 0 && c.JSONWebKeys != nil {
65+
if len(c.JSONWebKeysURI) > 0 && c.GetJSONWebKeys() != nil {
6666
return errorsx.WithStack(ErrInvalidClientMetadata.WithHint("Fields jwks and jwks_uri can not both be set, you must choose one."))
6767
}
6868

69-
if c.JSONWebKeys != nil && c.JSONWebKeys.JSONWebKeySet != nil {
70-
for _, k := range c.JSONWebKeys.Keys {
69+
if jsonWebKeys := c.GetJSONWebKeys(); jsonWebKeys != nil {
70+
for _, k := range jsonWebKeys.Keys {
7171
if !k.Valid() {
7272
return errorsx.WithStack(ErrInvalidClientMetadata.WithHint("Invalid JSON web key in set."))
7373
}

client/validator_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ func TestValidate(t *testing.T) {
112112
return true
113113
},
114114
},
115+
{
116+
in: &Client{ID: "foo", JSONWebKeys: new(x.JoseJSONWebKeySet), JSONWebKeysURI: "https://example.org/jwks.json"},
117+
check: func(t *testing.T, c *Client) {
118+
assert.Nil(t, c.GetJSONWebKeys())
119+
},
120+
},
115121
{
116122
in: &Client{ID: "foo", PostLogoutRedirectURIs: []string{"https://bar/"}, RedirectURIs: []string{"https://foo/"}},
117123
assertErr: assert.Error,

0 commit comments

Comments
 (0)