Class: ResoWebApi::Authentication::TokenAuth

Inherits:
AuthStrategy show all
Defined in:
lib/reso_web_api/authentication/token_auth.rb

Overview

This implements a basic token authentication, in which a username/password (or API key / secret) combination is sent to a special token endpoint in exchange for a HTTP Bearer token with a limited lifetime.

Constant Summary

Constants inherited from BaseClient

BaseClient::USER_AGENT

Instance Attribute Summary

Attributes inherited from AuthStrategy

#access

Instance Method Summary collapse

Methods inherited from AuthStrategy

#ensure_valid_access!, #reset

Methods inherited from BaseClient

#headers

Instance Method Details

#authenticateObject


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/reso_web_api/authentication/token_auth.rb', line 12

def authenticate
  response = connection.post nil, auth_params
  body = JSON.parse response.body

  unless response.success?
    message = "#{response.reason_phrase}: #{body['error'] || response.body}"
    raise Errors::AccessDenied, response: response, message: message
  end

  Access.new(body)
end

#connectionObject


24
25
26
# File 'lib/reso_web_api/authentication/token_auth.rb', line 24

def connection
  super.basic_auth(client_id, client_secret) && super
end