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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/omniauth/strategies/eloqua.rb', line 36
def callback_phase
error = request.params["error_reason"] || request.params["error"]
if error
fail!(error, CallbackError.new(request.params["error"],
request.params["error_description"] ||
request.params["error_reason"], request.params["error_uri"]))
else
conn = Faraday.new(:url => 'https://login.eloqua.com/auth/'\
'oauth2/token') do |faraday|
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
token = Base64.strict_encode64("#{options.client_id.strip}:"\
"#{options.client_secret.strip}").strip
result = conn.post do |req|
req.['Content-Type'] = 'application/json'
req.['Authorization'] = "Basic #{token}"
req.body = "{ 'grant_type': 'authorization_code', 'code': "\
"'#{request.params["code"]}', 'redirect_uri': "\
"'#{callback_url}?response_type=code&state="\
"#{request.params['state']}' }"
end
@access_token = result
result = JSON.parse(result.body)
if @access_token.status != 200
fail!(result['error'], Exception.new(result['error_description']))
else
env['omniauth.auth'] = auth_hash(result)
call_app!
end
end
rescue ::OAuth2::Error, CallbackError => e
fail!(:invalid_credentials, e)
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
fail!(:timeout, e)
rescue ::SocketError => e
fail!(:failed_to_connect, e)
end
|