Method: Dnsimple::Client::Oauth#exchange_authorization_for_token

Defined in:
lib/dnsimple/client/oauth.rb

#exchange_authorization_for_token(code, client_id, client_secret, options = {}) ⇒ String

Exchange the short-lived authorization code for an access token you can use to authenticate your API calls.

Parameters:

  • client_id (String)

    Client Id you received when the application was registered with DNSimple.

  • client_secret (String)

    Client Secret you received when the application was registered with DNSimple.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :redirect_uri (String)

    The redirect URL sent for the authorization, used to validate the request.

Returns:

  • (String)

    The url to redirect the user to authorize.

See Also:



16
17
18
19
20
21
22
# File 'lib/dnsimple/client/oauth.rb', line 16

def exchange_authorization_for_token(code, client_id, client_secret, options = {})
  attributes = { code: code, client_id: client_id, client_secret: client_secret, grant_type: "authorization_code" }
  attributes[:state] = options.delete(:state) if options.key?(:state)
  attributes[:redirect_uri] = options.delete(:redirect_uri) if options.key?(:redirect_uri)
  response = client.post(Client.versioned("/oauth/access_token"), attributes, options)
  Struct::OauthToken.new(response)
end