@@ -75,6 +75,8 @@ def request_token(params)
7575 if scope = Util . arglist ( params . delete ( :scope ) )
7676 params [ :scope ] = Util . strlist ( scope )
7777 end
78+ client_assertion = params [ :client_assertion ]
79+ params . delete ( :client_assertion )
7880 headers = { 'content-type' => FORM_UTF8 , 'accept' => JSON_UTF8 }
7981 if @client_auth_method == 'client_secret_basic' && @client_secret && @client_id
8082 if @basic_auth
@@ -88,6 +90,10 @@ def request_token(params)
8890 params [ :client_secret ] = @client_secret
8991 elsif @client_id && params [ :code_verifier ]
9092 params [ :client_id ] = @client_id
93+ elsif client_assertion && @client_id && @client_secret . nil?
94+ params [ :client_id ] = @client_id
95+ params [ :client_assertion ] = client_assertion
96+ params [ :client_assertion_type ] = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
9197 else
9298 headers [ 'X-CF-ENCODED-CREDENTIALS' ] = 'true'
9399 headers [ 'authorization' ] = Http . basic_auth ( CGI . escape ( @client_id || '' ) , CGI . escape ( @client_secret || '' ) )
@@ -129,6 +135,7 @@ def jkey(k) @key_style ? k : k.to_s end
129135 # * +:symbolize_keys+, if true, returned hash keys are symbols.
130136 def initialize ( target , client_id , client_secret = nil , options = { } )
131137 @target , @client_id , @client_secret = target , client_id , client_secret
138+ @client_assertion = options [ :client_assertion ] || nil
132139 @token_target = options [ :token_target ] || target
133140 @key_style = options [ :symbolize_keys ] ? :sym : nil
134141 @basic_auth = options [ :basic_auth ] == true ? true : false
@@ -310,8 +317,8 @@ def owner_password_credentials_grant(credentials)
310317 # Uses the instance client credentials to get a token with a client
311318 # credentials grant. See http://tools.ietf.org/html/rfc6749#section-4.4
312319 # @return [TokenInfo]
313- def client_credentials_grant ( scope = nil )
314- request_token ( grant_type : 'client_credentials' , scope : scope )
320+ def client_credentials_grant ( scope = nil , client_assertion = nil )
321+ request_token ( grant_type : 'client_credentials' , scope : scope , client_assertion : client_assertion )
315322 end
316323
317324 # Uses the instance client credentials and the given +refresh_token+ to get
0 commit comments