lib/soaspec/o_auth2.rb in soaspec-0.3.10 vs lib/soaspec/o_auth2.rb in soaspec-0.3.11

- old
+ new

@@ -53,10 +53,11 @@ # @option params_sent [token_url] URL to retrieve OAuth token from. @Note this can be set globally instead of here # @option params_sent [client_id] Client ID # @option params_sent [client_secret] Client Secret # @option params_sent [username] Username used in password grant # @option params_sent [password] Password used in password grant + # @option params_sent [resource] Api server that handles authenticated requests # @option params_sent [security_token] Security Token used in password grant # @param [String] api_username Username to use which can be set by Soaspec::ExchangeHandler def initialize(params_sent, api_username = nil) self.retry_count = 0 # No initial tries at getting access token params = params_sent.transform_keys_to_symbols @@ -127,20 +128,26 @@ # Payload to add to o-auth request dependent on params provided # @return [Hash] Payload for retrieving OAuth access token def payload payload = { client_id: params[:client_id], client_secret: params[:client_secret] } - payload.merge(if params[:password] && params[:username] - { - grant_type: 'password', username: params[:username], - password: password - }.merge multipart true - else - { grant_type: 'client_credentials' }.merge multipart false - end) + payload.merge!(if params[:password] && params[:username] + password_grant_type_params + else + { grant_type: 'client_credentials' }.merge multipart false + end) + payload[:resource] = params[:resource] if params[:resource] + payload end private + + def password_grant_type_params + { + grant_type: 'password', username: params[:username], + password: password + }.merge multipart true + end # @param [Boolean] default Default value for multipart # @return [Hash] Multipart set to true if not set and is grant_type password def multipart(default) return { multipart: true } if (params[:multipart].nil? && default) || params[:multipart]