Class: Salesforce::Service
Constant Summary
collapse
- SALESFORCE_HOST =
"https://#{Settings.salesforce.env == 'prod' ? 'login' : 'test'}.salesforce.com".freeze
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
#claim_set ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/salesforce/service.rb', line 20
def claim_set
{
iss: self.class::CONSUMER_KEY,
sub: self.class::SALESFORCE_USERNAME,
aud: SALESFORCE_HOST,
exp: Time.now.utc.to_i
}
end
|
#get_client ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/salesforce/service.rb', line 40
def get_client
Restforce.new(
oauth_token: get_oauth_token,
instance_url: self.class.module_parent::Configuration::SALESFORCE_INSTANCE_URL,
api_version: '41.0'
)
end
|
#get_oauth_token ⇒ Object
33
34
35
36
37
38
|
# File 'lib/salesforce/service.rb', line 33
def get_oauth_token
body = with_monitoring { request(:post, '', oauth_params).body }
Sentry.(oauth_response_body: body)
body['access_token']
end
|
#jwt_bearer_token ⇒ Object
16
17
18
|
# File 'lib/salesforce/service.rb', line 16
def jwt_bearer_token
JWT.encode(claim_set, private_key, 'RS256')
end
|
#oauth_params ⇒ Object
9
10
11
12
13
14
|
# File 'lib/salesforce/service.rb', line 9
def oauth_params
{
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: jwt_bearer_token
}
end
|
#private_key ⇒ Object
29
30
31
|
# File 'lib/salesforce/service.rb', line 29
def private_key
OpenSSL::PKey::RSA.new(File.read(self.class::SIGNING_KEY_PATH))
end
|