Class: OmniAuth::Strategies::Salesking
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Salesking
- Defined in:
- lib/sk_sdk/omni_auth/salesking.rb
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#callback_phase ⇒ Object
Monkey-patching to inject subdomain again into OmniAuth.
-
#initialize(app, client_id, client_secret, sk_url, scope) ⇒ Salesking
constructor
SalesKing requires a subdomain up front It needs to be provided in a form and retrieved from the request The one on init is not used as it is grabbed from the session later.
-
#request_phase ⇒ Object
inject salesking url and scope into OmniAuth.
-
#set_sk_url ⇒ String
Each company has it’s own subdomain so the url must be dynamic.
-
#user_data ⇒ Hash
User currently logged in.
- #user_info ⇒ Object
Constructor Details
#initialize(app, client_id, client_secret, sk_url, scope) ⇒ Salesking
SalesKing requires a subdomain up front It needs to be provided in a form and retrieved from the request The one on init is not used as it is grabbed from the session later
17 18 19 20 21 22 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 17 def initialize(app, client_id, client_secret, sk_url, scope) @base_url = sk_url @scope = scope = {:access_token_path => '/oauth/token'} super(app, :salesking, client_id, client_secret, ) end |
Instance Method Details
#auth_hash ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 54 def auth_hash OmniAuth::Utils.deep_merge(super, { # 'uid' => "#{user_data['current_company']['company']['id']}.#{user_data['id']}", 'uid' => user_data['id'], 'user_info' => user_info, 'credentials' => { 'expires_in' => @access_token.expires_in }, 'extra' => {'user_hash' => user_data} }) end |
#callback_phase ⇒ Object
Monkey-patching to inject subdomain again into OmniAuth
32 33 34 35 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 32 def callback_phase set_sk_url super end |
#request_phase ⇒ Object
inject salesking url and scope into OmniAuth
25 26 27 28 29 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 25 def request_phase [:scope] = @scope set_sk_url super end |
#set_sk_url ⇒ String
Each company has it’s own subdomain so the url must be dynamic. This is achieved by replacing the * with the subdomain from the session
69 70 71 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 69 def set_sk_url [:site] = @base_url.gsub('*', session[:subdomain]).gsub(/\/\z/, '' ) end |
#user_data ⇒ Hash
Returns user currently logged in.
38 39 40 41 42 43 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 38 def user_data @data ||= begin ret = MultiJson.decode(@access_token.get('api/users/current')) ret['user'] end end |
#user_info ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/sk_sdk/omni_auth/salesking.rb', line 45 def user_info { 'email' => (user_data["email"] if user_data["email"]), 'first_name' => user_data["first_name"], 'last_name' => user_data["last_name"], 'name' => "#{user_data['first_name']} #{user_data['last_name']}" } end |