Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/omniauth/strategies/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "securerandom"
require "socket" # for SocketError
require "timeout" # for Timeout::Error
require "logger"

module OmniAuth
module Strategies
Expand Down Expand Up @@ -45,7 +46,9 @@ def client
end

def request_phase
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
url = client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
log("[request_phase - url] #{url}")
redirect url
end

def authorize_params
Expand All @@ -56,11 +59,14 @@ def authorize_params
@env["rack.session"] ||= {}
end
session["omniauth.state"] = params[:state]
log("[authorize_params] #{params.inspect}")
params
end

def token_params
options.token_params.merge(options_for("token"))
params = options.token_params.merge(options_for("token"))
log("[token_params] #{params.inspect}")
params
end

def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
Expand All @@ -84,6 +90,10 @@ def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength

protected

def log(message)
::Logger.new($stdout).info(message) if ENV['OAUTH_DEBUG'] == 'true'
end

def build_access_token
verifier = request.params["code"]
client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
Expand Down