Skip to content

Commit 93bac69

Browse files
authored
feature: support jwt client configuration (#93)
allow to set JWKS configuration for client authentication based on private_key_jwt standard
1 parent fe9cc20 commit 93bac69

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

lib/uaa/scim.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,28 @@ def change_secret(client_id, new_secret, old_secret = nil)
369369
"#{type_info(:client, :path)}/#{Addressable::URI.encode(client_id)}/secret", req, headers))
370370
end
371371

372+
# Change client jwt trust configuration.
373+
# * For a client to change its jwt client trust, the token in @auth_header must contain
374+
# "client.trust" scope.
375+
# * For an admin to set a client secret, the token in @auth_header must contain
376+
# "uaa.admin" scope.
377+
# @see https://docs.cloudfoundry.org/api/uaa/index.html#change-client-jwt
378+
# @param [String] client_id the {Scim} +id+ attribute of the client
379+
# @param [String] jwks_uri the URI to token endpoint
380+
# @param [String] jwks the JSON Web Key Set
381+
# @param [String] kid If changeMode is DELETE provide the id of key
382+
# @param [String] changeMode Change mode, possible is ADD, UPDATE, DELETE
383+
# @return [Hash] success message from server
384+
def change_clientjwt(client_id, jwks_uri = nil, jwks = nil, kid = nil, changeMode = nil)
385+
req = {"client_id" => client_id }
386+
req["jwks_uri"] = jwks_uri if jwks_uri
387+
req["jwks"] = jwks if jwks
388+
req["kid"] = kid if kid
389+
req["changeMode"] = changeMode if changeMode
390+
json_parse_reply(@key_style, *json_put(@target,
391+
"#{type_info(:client, :path)}/#{Addressable::URI.encode(client_id)}/clientjwt", req, headers))
392+
end
393+
372394
def unlock_user(user_id)
373395
req = {"locked" => false}
374396
json_parse_reply(@key_style, *json_patch(@target,

spec/scim_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,30 @@ def check_headers(headers, content, accept, zone)
160160
result['id'].should == 'id12345'
161161
end
162162

163+
it "add a client's jwt trust using jwks_uri" do
164+
subject.set_request_handler do |url, method, body, headers|
165+
url.should == "#{@target}/oauth/clients/id12345/clientjwt"
166+
method.should == :put
167+
check_headers(headers, :json, :json, nil)
168+
body.should include('"jwks_uri":"http://localhost:8080/uaa/token_keys"')
169+
[200, '{"id":"id12345"}', {'content-type' => 'application/json'}]
170+
end
171+
result = subject.change_clientjwt('id12345', 'http://localhost:8080/uaa/token_keys')
172+
result['id'].should == 'id12345'
173+
end
174+
175+
it "add a client's jwt trust using jwks" do
176+
subject.set_request_handler do |url, method, body, headers|
177+
url.should == "#{@target}/oauth/clients/id12345/clientjwt"
178+
method.should == :put
179+
check_headers(headers, :json, :json, nil)
180+
body.should include('"jwks":"keys"')
181+
[200, '{"id":"id12345"}', {'content-type' => 'application/json'}]
182+
end
183+
result = subject.change_clientjwt('id12345', nil, 'keys')
184+
result['id'].should == 'id12345'
185+
end
186+
163187
it 'unlocks a user' do
164188
subject.set_request_handler do |url, method, body, headers|
165189
url.should == "#{@target}/Users/id12345/status"

0 commit comments

Comments
 (0)