Method: DocuSign_Maestro::ApiClient#generate_access_token
- Defined in:
- lib/docusign_maestro/client/api_client.rb
permalink #generate_access_token(client_id, client_secret, code) ⇒ Object
GenerateAccessToken will exchange the authorization code for an access token and refresh tokens.
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/docusign_maestro/client/api_client.rb', line 565 def generate_access_token(client_id, client_secret, code) raise ArgumentError.new('client_id cannot be empty') if client_id.empty? raise ArgumentError.new('client_secret cannot be empty') if client_secret.empty? raise ArgumentError.new('code cannot be empty') if code.empty? authcode = "Basic " + Base64.strict_encode64("#{client_id}:#{client_secret}") params = { :header_params => { "Authorization" => authcode, "Content-Type" => "application/x-www-form-urlencoded" }, :form_params => { "grant_type" => 'authorization_code', "code" => code, }, :return_type => 'OAuth::OAuthToken', :oauth => true } token, status_code, headers = self.call_api("POST", '/oauth/token', params) if status_code == 200 self.default_headers.store('Authorization', "#{token.token_type} #{token.access_token}") token end end |