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
|
# File 'lib/omniauth-surveymonkey/omniauth/strategies/surveymonkey.rb', line 16
def callback_phase
connection = ::Faraday.new url: 'https://api.surveymonkey.net' do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter ::Faraday.default_adapter
end
form_fields = {
client_id: options.client_id,
client_secret: options.client_secret,
code: request.params['code'],
redirect_uri: (full_host + callback_path),
grant_type: 'authorization_code'
}
response = connection.post "/oauth/token?api_key=#{options.api_key}", form_fields
json = ::MultiJson.load response.body
options.access_token = json['access_token']
if options.access_token
connection.authorization :Bearer, options.access_token
info = connection.get "/v3/users/me?api_key=#{options.api_key}"
json = ::MultiJson.load info.body
options.username = json['username']
options.first_name = json['first_name']
options.last_name = json['last_name']
options.account_type = json['account_type']
options.language = json['language']
options.email = json['email']
options.surveymonkey_id = json['id'].to_i
end
super
end
|