Class: OmniAuth::Strategies::Forcedotcom

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/Salesforce/oauth2/forcedotcom.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Forcedotcom

Returns a new instance of Forcedotcom.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/Salesforce/oauth2/forcedotcom.rb', line 9

def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
  client_options = {
    :site => 'https://login.salesforce.com',
    :authorize_path => '/services/oauth2/authorize',
    :access_token_path => '/services/oauth2/token'
  }

  # 'code' locks you into one org; 'token' works across all orgs.
  options.merge!(:response_type => 'token', :grant_type => 'authorization_code')

  super(app, :forcedotcom, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/Salesforce/oauth2/forcedotcom.rb', line 22

def auth_hash
  data = user_data
  OmniAuth::Utils.deep_merge(super, {
      'uid' => @access_token['id'],
      'credentials' => {
        'instance_url' => @access_token['instance_url']
      },
      'extra' => {'user_hash' => data},
      'user_info' => {
        'email' => data['email'],
        'name' => data['display_name']
      }
    })
end

#user_dataObject



37
38
39
40
41
42
43
44
45
# File 'lib/Salesforce/oauth2/forcedotcom.rb', line 37

def user_data
  @data ||= MultiJson.decode(@access_token.get(@access_token['id']))
rescue ::OAuth2::HTTPError => e
  if e.response.status == 302
    @data ||= MultiJson.decode(@access_token.get(e.response.headers['location']))
  else
    raise e
  end
end