Class: OpenStax::Salesforce::Configuration
- Inherits:
-
Object
- Object
- OpenStax::Salesforce::Configuration
- Defined in:
- lib/openstax_salesforce.rb
Overview
See config/initializers/openstax_salesforce.rb for documentation on options
Constant Summary collapse
- GENERIC_LOGIN_DOMAINS =
Salesforce rejects client credentials token requests sent to these
%w[login.salesforce.com test.salesforce.com].freeze
Instance Attribute Summary collapse
- #api_version ⇒ Object
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
- #login_domain ⇒ Object
-
#password ⇒ Object
Returns the value of attribute password.
-
#security_token ⇒ Object
Returns the value of attribute security_token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#username_password_flow? ⇒ Boolean
Salesforce retires the OAuth username-password flow in Spring '27, so a username is now optional: leave it unset to use client credentials.
- #validate! ⇒ Object
Instance Attribute Details
#api_version ⇒ Object
43 44 45 |
# File 'lib/openstax_salesforce.rb', line 43 def api_version @api_version ||= '61.0' end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
41 42 43 |
# File 'lib/openstax_salesforce.rb', line 41 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
41 42 43 |
# File 'lib/openstax_salesforce.rb', line 41 def consumer_secret @consumer_secret end |
#login_domain ⇒ Object
47 48 49 |
# File 'lib/openstax_salesforce.rb', line 47 def login_domain @login_domain ||= 'test.salesforce.com' end |
#password ⇒ Object
Returns the value of attribute password.
41 42 43 |
# File 'lib/openstax_salesforce.rb', line 41 def password @password end |
#security_token ⇒ Object
Returns the value of attribute security_token.
41 42 43 |
# File 'lib/openstax_salesforce.rb', line 41 def security_token @security_token end |
#username ⇒ Object
Returns the value of attribute username.
41 42 43 |
# File 'lib/openstax_salesforce.rb', line 41 def username @username end |
Instance Method Details
#username_password_flow? ⇒ Boolean
Salesforce retires the OAuth username-password flow in Spring '27, so a username is now optional: leave it unset to use client credentials.
53 54 55 |
# File 'lib/openstax_salesforce.rb', line 53 def username_password_flow? !username.nil? end |
#validate! ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/openstax_salesforce.rb', line 57 def validate! raise(IllegalState, "The Salesforce consumer key is missing") if consumer_key.nil? raise(IllegalState, "The Salesforce consumer secret is missing") if consumer_secret.nil? if username_password_flow? raise(IllegalState, "The Salesforce password is missing") if password.nil? raise(IllegalState, "The Salesforce security token is missing") if security_token.nil? return end # Half-removed credentials would otherwise switch flows silently unless password.nil? && security_token.nil? raise( IllegalState, "The Salesforce password and security token only apply to the username-password " \ "flow. Remove them to use client credentials, or set a username to keep using " \ "the username-password flow." ) end if GENERIC_LOGIN_DOMAINS.include?(login_domain) raise( IllegalState, "The Salesforce client credentials flow requires the org's My Domain as the " \ "login domain (e.g. myorg.my.salesforce.com), not #{login_domain}" ) end end |