Module: Skykick::Authentication
- Included in:
- API
- Defined in:
- lib/skykick/authentication.rb
Overview
Deals with authentication flow and stores it within global configuration
Instance Method Summary collapse
-
#auth_token(options = {}) ⇒ Object
(also: #login)
Authorize to the Skykick portal and return access_token.
Instance Method Details
#auth_token(options = {}) ⇒ Object Also known as: login
Authorize to the Skykick portal and return access_token
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/skykick/authentication.rb', line 9 def auth_token( = {}) raise ConfigurationError.new 'Client id and/or secret not configured' unless client_id && client_secret c = connection c.request :authorization, :basic, client_id, client_secret response = c.post('/auth/token') do |request| request.headers['Content-Type'] = 'application/x-www-form-urlencoded' request.body = URI.encode_www_form( api_access_token_params ) end api_process_token(response.body) self.access_token rescue Faraday::ForbiddenError => e raise AuthenticationError.new 'Unauthorized; response ' + e.to_s end |