Class: Sorcery::Providers::Salesforce
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/salesforce.rb
Overview
This class adds support for OAuth with salesforce.com.
config.salesforce.key = <key>
config.salesforce.secret = <secret>
...
Instance Attribute Summary collapse
-
#auth_url ⇒ Object
Returns the value of attribute auth_url.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_url ⇒ Object
Returns the value of attribute token_url.
Attributes inherited from Base
#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping
Instance Method Summary collapse
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Salesforce
constructor
A new instance of Salesforce.
-
#login_url(_params, _session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
-
#process_callback(params, _session) ⇒ Object
tries to login the user from access token.
Methods included from Sorcery::Protocols::Oauth2
#authorize_url, #build_client, #get_access_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Salesforce
Returns a new instance of Salesforce.
14 15 16 17 18 19 20 |
# File 'lib/sorcery/providers/salesforce.rb', line 14 def initialize super @site = 'https://login.salesforce.com' @auth_url = '/services/oauth2/authorize' @token_url = '/services/oauth2/token' end |
Instance Attribute Details
#auth_url ⇒ Object
Returns the value of attribute auth_url.
12 13 14 |
# File 'lib/sorcery/providers/salesforce.rb', line 12 def auth_url @auth_url end |
#scope ⇒ Object
Returns the value of attribute scope.
12 13 14 |
# File 'lib/sorcery/providers/salesforce.rb', line 12 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
12 13 14 |
# File 'lib/sorcery/providers/salesforce.rb', line 12 def token_url @token_url end |
Instance Method Details
#get_user_hash(access_token) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/sorcery/providers/salesforce.rb', line 22 def get_user_hash(access_token) user_info_url = access_token.params['id'] response = access_token.get(user_info_url) auth_hash(access_token).tap do |h| h[:user_info] = JSON.parse(response.body) h[:uid] = h[:user_info]['user_id'] end end |
#login_url(_params, _session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
34 35 36 |
# File 'lib/sorcery/providers/salesforce.rb', line 34 def login_url(_params, _session) (authorize_url: auth_url) end |
#process_callback(params, _session) ⇒ Object
tries to login the user from access token
39 40 41 42 43 44 45 |
# File 'lib/sorcery/providers/salesforce.rb', line 39 def process_callback(params, _session) args = {}.tap do |a| a[:code] = params[:code] if params[:code] end get_access_token(args, token_url: token_url, token_method: :post) end |