Class: OmniAuth::Strategies::Force
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Force
- Defined in:
- lib/omniauth/strategies/force.rb
Overview
Authenticate to force.com utilizing OAuth 2.0 and retrieve basic user information.
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #callback_phase ⇒ Object
-
#full_host ⇒ Object
Monkey patch scheme for callback url.
- #get_access_token(verifier) ⇒ Object
-
#initialize(app, consumer_key, consumer_secret, options = {}) ⇒ Force
constructor
A new instance of Force.
- #request_phase ⇒ Object
- #user_data ⇒ Object
- #user_info ⇒ Object
Constructor Details
#initialize(app, consumer_key, consumer_secret, options = {}) ⇒ Force
Returns a new instance of Force.
15 16 17 18 19 20 21 |
# File 'lib/omniauth/strategies/force.rb', line 15 def initialize(app, consumer_key, consumer_secret, = {}) [:site] = 'https://login.salesforce.com/' [:authorize_path] = '/services/oauth2/authorize' [:access_token_path] = '/services/oauth2/token' super(app, :force, consumer_key, consumer_secret, ) end |
Instance Method Details
#auth_hash ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/omniauth/strategies/force.rb', line 75 def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user_data['user_id'], 'user_info' => user_info, 'extra' => {'user_hash' => user_data}, 'credentials' => { 'instance_url' => @access_token['instance_url'] } }) end |
#callback_phase ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/omniauth/strategies/force.rb', line 52 def callback_phase if request.params['error'] || request.params['error_reason'] raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']) end @access_token = get_access_token(request.params['code']) @env['omniauth.auth'] = auth_hash call_app! rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e fail!(:invalid_credentials, e) end |
#full_host ⇒ Object
Monkey patch scheme for callback url
28 29 30 31 32 33 34 |
# File 'lib/omniauth/strategies/force.rb', line 28 def full_host uri = URI.parse(request.url) uri.path = '' uri.query = nil uri.scheme = request.env['HTTP_X_FORWARDED_PROTO'] || request.scheme uri.to_s end |
#get_access_token(verifier) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omniauth/strategies/force.rb', line 41 def get_access_token(verifier) access_token = client.web_server.get_access_token( verifier, :redirect_uri => callback_url, :grant_type => 'authorization_code').tap do |token| token.token_param = 'oauth_token' end access_token end |
#request_phase ⇒ Object
36 37 38 39 |
# File 'lib/omniauth/strategies/force.rb', line 36 def request_phase [:response_type] ||= "code" super end |
#user_data ⇒ Object
23 24 25 |
# File 'lib/omniauth/strategies/force.rb', line 23 def user_data @data ||= MultiJson.decode(@access_token.get(@access_token['id'])) end |
#user_info ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omniauth/strategies/force.rb', line 64 def user_info { 'nickname' => user_data['nick_name'], 'email' => user_data['email'], 'name' => user_data['display_name'], 'urls' => { 'Force' => user_data['urls']['profile'], } } end |