Class: CARMA::Client::MuleSoftAuthTokenClient
Defined Under Namespace
Classes: GetAuthTokenError
Constant Summary
collapse
- STATSD_KEY_PREFIX =
'api.carma.mulesoft.auth'
- GRANT_TYPE =
'client_credentials'
- SCOPE =
'DTCWriteResource'
Instance Method Summary
collapse
#increment, #increment_failure, #increment_total, #with_monitoring
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Instance Method Details
#auth_token_path ⇒ Object
58
59
60
|
# File 'lib/carma/client/mule_soft_auth_token_client.rb', line 58
def auth_token_path
config.settings.auth_token_path
end
|
#client_id ⇒ Object
50
51
52
|
# File 'lib/carma/client/mule_soft_auth_token_client.rb', line 50
def client_id
config.settings.client_id
end
|
#client_secret ⇒ Object
54
55
56
|
# File 'lib/carma/client/mule_soft_auth_token_client.rb', line 54
def client_secret
config.settings.client_secret
end
|
#new_bearer_token ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/carma/client/mule_soft_auth_token_client.rb', line 18
def new_bearer_token
with_monitoring do
response = perform(:post,
auth_token_path,
params,
,
{ timeout: config.timeout })
return JSON.parse(response.body)['access_token'] if response.status == 200
raise GetAuthTokenError, "Response: #{response}"
end
end
|
#params ⇒ Object
34
35
36
37
38
39
|
# File 'lib/carma/client/mule_soft_auth_token_client.rb', line 34
def params
URI.encode_www_form({
grant_type: GRANT_TYPE,
scope: SCOPE
})
end
|
41
42
43
44
45
46
47
48
|
# File 'lib/carma/client/mule_soft_auth_token_client.rb', line 41
def
basic_auth = Base64.urlsafe_encode64("#{client_id}:#{client_secret}")
{
'Authorization' => "Basic #{basic_auth}",
'Content-Type' => 'application/x-www-form-urlencoded'
}
end
|