Class: Keywright::RefreshTokenRequest
- Defined in:
- lib/keywright/refresh_token_request.rb
Instance Method Summary collapse
-
#submit(**arguments) ⇒ Object
The submit method makes a request to retrieve the OAuth token from the authorization server given the refresh_token.
Methods inherited from Request
Constructor Details
This class inherits a constructor from Keywright::Request
Instance Method Details
#submit(**arguments) ⇒ Object
The submit method makes a request to retrieve the OAuth token from the authorization server given the refresh_token.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/keywright/refresh_token_request.rb', line 8 def submit( **arguments ) refresh_token = arguments[ :refresh_token ] raise ArgumentError.new( 'A `refresh_token` is required.' ) \ if refresh_token.nil? token_uri = arguments[ :token_uri ] || @configuration[ :token_uri ] raise ArgumentError.new( 'The token uri must be provided or configured.' ) \ unless UriHelpers.valid?( token_uri ) client_id = arguments[ :client_id ] || @configuration[ :client_id ] client_secret = arguments[ :client_secret ] || @configuration[ :client_secret ] raise ArgumentError.new( 'The client credentials must be provided or configured.' ) \ if client_id.nil? || client_secret.nil? response = Keywright.connection.post( token_uri ) do | request | request.headers[ 'Authorization' ] = "Basic #{Base64.strict_encode64( "#{client_id}:#{client_secret}")}" request.body = { grant_type: 'refresh_token', refresh_token: refresh_token } yield( request ) if block_given? end body = JSON.parse( response.body, symbolize_names: true ) rescue nil result = nil if response.success? result = TokenResult.new( body ) else result = ErrorResult.new( response.status, body ) end ResponseMethods.install( response, result ) end |