Module: AuthTool::OAuth1

Defined in:
lib/auth_tool/oauth_1.rb

Class Method Summary collapse

Class Method Details

.call(client, http_verb = 'get', uri, params) ⇒ Hash

Makes an authenticated call to the API resource. Called by AuthTool::call.

Parameters:

  • client (AuthTool::Client)

    The client containing the API information.

  • uri (String)

    The API endpoint to hit.

  • params (Hash)

    Hash of additional parameters for the call.

Returns:

  • (Hash)

    The endpoint’s response.



62
63
64
65
66
67
68
69
# File 'lib/auth_tool/oauth_1.rb', line 62

def self.call(client, http_verb = 'get', uri, params)
  header = params.delete('header') if params.has_key? 'header'
  body = params.delete('body') if params.has_key? 'body'
  conn = Faraday.new(:params => params)
  options = {:method => http_verb, :header => header, :body => body, :uri => uri, :connection => conn}
  response = client.signet.fetch_protected_resource(options)
  return JSON.parse(response.body)
end

.receive(client, response) ⇒ Object

Handles OAuth 1.0 callback procedure. Called by AuthTool::receive.

Parameters:

  • client (AuthTool::Client)

    The client containing the API information.

  • response (Hash)

    The response to the callback url (verification information).



41
42
43
44
45
46
# File 'lib/auth_tool/oauth_1.rb', line 41

def self.receive(client, response)
  verifier = response['oauth_verifier'] if response.has_key?('oauth_verifier')
  verifier = response[:oauth_verifier] if response.has_key?(:oauth_verifier)
  credential = client.signet.fetch_token_credential!(:verifier => verifier)
  client.token = credential.to_hash
end

.redirect_url(client, options = {}) ⇒ String

Returns redirect url for user authentication with the service

Parameters:

  • client (AuthTool::Client)

    The AuthTool Client object.

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

    The signet configuration options.

    • :signature_method The signature method. Defaults to ‘HMAC-SHA1’.

    • :additional_parameters Non-standard additional parameters.

    • :realm The Authorization realm. See RFC 2617.

    • :connection The HTTP connection to use. Must be of type Faraday::Connection

Returns:

  • (String)

    The url to redirect to.



26
27
28
29
30
# File 'lib/auth_tool/oauth_1.rb', line 26

def self.redirect_url(client,options = {})
  client.signet.fetch_temporary_credential!(options)
  url = client.signet.authorization_uri
  return url
end