Class: NoyoAccounts::Client::Services::AuthService
- Inherits:
-
NoyoApi::Client::Services::BaseService
- Object
- NoyoApi::Client::Services::BaseService
- NoyoAccounts::Client::Services::AuthService
- Includes:
- HTTParty, NoyoApi::Client::UserAgent
- Defined in:
- lib/noyo_accounts/client/services/auth_service.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorize(client_id, client_secret) ⇒ Object
-
#initialize ⇒ AuthService
constructor
A new instance of AuthService.
Methods included from NoyoApi::Client::UserAgent
Methods inherited from NoyoApi::Client::Services::BaseService
resource, resource_path, root_path
Constructor Details
#initialize ⇒ AuthService
Returns a new instance of AuthService.
11 12 13 14 |
# File 'lib/noyo_accounts/client/services/auth_service.rb', line 11 def initialize # Get the latest config value, in case it changed self.class.base_uri(NoyoApi::Api.config.accounts_base_uri) end |
Class Method Details
.authorize_path ⇒ Object
16 17 18 |
# File 'lib/noyo_accounts/client/services/auth_service.rb', line 16 def self. '/auth/public/token' end |
Instance Method Details
#authorize(client_id, client_secret) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/noyo_accounts/client/services/auth_service.rb', line 20 def (client_id, client_secret) auth = { username: client_id, password: client_secret, } body = { grant_type: 'client_credentials', } = { body: body.to_json, basic_auth: auth, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => self.class.user_agent, }, } result = self.class.post(self.class., ) raise 'Bad credentials.' if result.code == 401 parse_httparty_response(result)&.[]('access_token') end |