Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions lib/omniauth/strategies/google_oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ def custom_build_access_token
elsif verify_token(request.params['id_token'], request.params['access_token'])
::OAuth2::AccessToken.from_hash(client, request.params.dup)
else
orig_build_access_token
verifier = request.params["code"]
client.auth_code.get_token(verifier, get_token_options(callback_url), deep_symbolize(options.auth_token_params))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: we should use the same coding style as above.

deep_symbolize(options.auth_token_params || {})

end
end
alias_method :orig_build_access_token, :build_access_token
alias_method :build_access_token, :custom_build_access_token

private

def callback_url
options[:redirect_uri] || (full_host + script_name + callback_path)
end

def get_token_options(redirect_uri)
{ :redirect_uri => redirect_uri }.merge(token_params.to_hash(:symbolize_keys => true))
end
Expand Down
19 changes: 16 additions & 3 deletions spec/omniauth/strategies/google_oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,15 @@
end

describe '#callback_path' do
it 'has the correct callback path' do
it 'has the correct default callback path' do
expect(subject.callback_path).to eq('/auth/google_oauth2/callback')
end

it 'should set the callback_path parameter if present' do
@options = {:callback_path => '/auth/foo/callback'}
expect(subject.callback_path).to eq('/auth/foo/callback')
end

end

describe '#extra' do
Expand Down Expand Up @@ -531,10 +537,17 @@
expect(token.client).to eq(:client)
end

it 'should call super if this is not an AJAX request' do
it 'should use callback_url without query_string if this is not an AJAX request' do
allow(request).to receive(:xhr?).and_return(false)
allow(request).to receive(:params).and_return('code' => 'valid_code')
expect(subject).to receive(:orig_build_access_token)

client = double(:client)
auth_code = double(:auth_code)
allow(client).to receive(:auth_code).and_return(auth_code)
allow(subject).to receive(:callback_url).and_return('redirect_uri_without_query_string')

expect(subject).to receive(:client).and_return(client)
expect(auth_code).to receive(:get_token).with('valid_code', { :redirect_uri => 'redirect_uri_without_query_string'}, {})
subject.build_access_token
end
end
Expand Down