class CapitalOnTap::Auth
Constants
- DEFAULT_GRANT_TYPE
- REFRESH_GRANT_TYPE
- TOKEN_PATH
Public Class Methods
obtain_token()
click to toggle source
# File lib/capital_on_tap/auth.rb, line 22 def self.obtain_token new.obtain_token end
refresh_access_token(refresh_token)
click to toggle source
# File lib/capital_on_tap/auth.rb, line 18 def self.refresh_access_token(refresh_token) new.refresh_access_token(refresh_token) end
Public Instance Methods
obtain_token()
click to toggle source
Requests a new token. The response will be something like:
{
scope: 'profile offline_access', token_type: 'Bearer', access_token: '<access_token>', expires_in: 1200, refresh_token: '<refresh_token>'
}
# File lib/capital_on_tap/auth.rb, line 35 def obtain_token token_request(token_params) end
refresh_access_token(refresh_token)
click to toggle source
# File lib/capital_on_tap/auth.rb, line 39 def refresh_access_token(refresh_token) return {} unless refresh_token refresh_params = token_params(grant_type: REFRESH_GRANT_TYPE, refresh_token: refresh_token) token_request(refresh_params) end
Private Instance Methods
client()
click to toggle source
# File lib/capital_on_tap/auth.rb, line 49 def client Faraday.new(url: config.base_auth_url) do |conn| conn.headers['Content-Type'] = 'application/x-www-form-urlencoded' conn.response :logger if config.debug? conn.adapter Faraday.default_adapter end end
config()
click to toggle source
# File lib/capital_on_tap/auth.rb, line 68 def config CapitalOnTap.configuration end
token_params(params = {})
click to toggle source
# File lib/capital_on_tap/auth.rb, line 72 def token_params(params = {}) { client_id: config.client_id, client_secret: config.client_secret, grant_type: DEFAULT_GRANT_TYPE, username: config.username, password: config.password }.merge(params) end
token_request(token_params)
click to toggle source
# File lib/capital_on_tap/auth.rb, line 57 def token_request(token_params) puts "[DEBUG] Sending #{token_params.inspect}" if config.debug? result = client.post do |req| req.url TOKEN_PATH req.body = URI.encode_www_form(token_params) end MultiJson.load(result.body, symbolize_keys: true) end