Module: Skykick::Authentication
- Included in:
- API
- Defined in:
- lib/skykick/authentication.rb
Overview
The ‘Skykick::Authentication` module handles the authentication flow for the Skykick API. It manages access tokens and stores them in the global configuration. This module provides methods to log in to the Skykick portal using client credentials.
Instance Method Summary collapse
-
#auth_token(_options = {}) ⇒ String
(also: #login)
Authenticates with the Skykick API and retrieves an access token.
Instance Method Details
#auth_token(_options = {}) ⇒ String Also known as: login
Authenticates with the Skykick API and retrieves an access token.
This method performs a client credentials flow to authenticate with the Skykick API. The access token is stored in the global configuration for subsequent API calls.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/skykick/authentication.rb', line 26 def auth_token( = {}) raise ConfigurationError.new 'Client id and/or secret not configured' unless client_id && client_secret con = connection con.request :authorization, :basic, client_id, client_secret response = con.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}" end |