Module: Sophos::Authentication
- Included in:
- API
- Defined in:
- lib/sophos/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 Sophos portal and return access_token.
Instance Method Details
#auth_token(options = {}) ⇒ Object Also known as: login
Authorize to the Sophos portal and return access_token
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sophos/authentication.rb', line 12 def auth_token( = {}) raise ConfigurationError.new 'Client id and/or secret not configured' unless client_id && client_secret # use id endpoint instead of global api response = connection.post(id_endpoint+'/api/v2/oauth2/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) setup_connection # use default endpoint and replace it with global endpoint self.access_token rescue Faraday::UnauthorizedError => e raise AuthenticationError.new 'Unauthorized; response ' + e.to_s end |