forked from omniauth/omniauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
salesforce.rb
60 lines (54 loc) · 1.7 KB
/
salesforce.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'omniauth/strategies/oauth2'
module OmniAuth
module Strategies
class Salesforce < OmniAuth::Strategies::OAuth2
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
client_options = {
:site => 'https://login.salesforce.com',
:authorize_url => '/services/oauth2/authorize',
:token_url => '/services/oauth2/token',
}
super(app, :salesforce, client_id, client_secret, client_options, options, &block)
end
def request_phase
options[:response_type] ||= 'code'
super
end
def callback_phase
options[:grant_type] ||= 'authorization_code'
super
end
def auth_hash
data = user_data
OmniAuth::Utils.deep_merge(
super, {
'uid' => @access_token['id'],
'credentials' => {
'issued_at' => @access_token['issued_at'],
'refresh_token' => @access_token.refresh_token,
'instance_url' => @access_token['instance_url'],
'signature' => @access_token['signature'],
},
'extra' => {
'user_hash' => data,
},
'user_info' => {
'email' => data['email'],
'name' => data['display_name'],
},
}
)
end
def user_data
@access_token.options[:header_format] = 'OAuth %s'
@data ||= @access_token.get(@access_token['id']).parsed
rescue ::OAuth2::Error => e
if e.response.status == 302
@data ||= @access_token.get(e.response.headers['location']).parsed
else
raise e
end
end
end
end
end