56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/omniauth/strategies/edwith_oauth2.rb', line 56
def build_access_token
verifier = request.params["code"]
clientId = options.client_id
clientSecret = options.client_secret
token_url = options.client_options[:token_url]
params = {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true))
params = {'grant_type' => 'authorization_code', 'code' => verifier}.merge(client.redirection_params).merge(params)
params = ::OAuth2::Authenticator.new(clientId, clientSecret, :request_body).apply(params)
opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
= params.delete(:headers) || {}
opts[:body] = params
opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
opts[:headers].merge!()
response = client.request(:post, token_url, opts)
if options[:raise_errors] && !(response.parsed.is_a?(Hash))
error = Error.new(response)
raise(error)
end
access_token_opts = deep_symbolize(options.auth_token_params)
::OAuth2::AccessToken.from_hash(client, response.parsed["data"].merge(access_token_opts))
end
|