Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use header auth mode for user and email requests #84

Merged
merged 1 commit into from Feb 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/omniauth/strategies/github.rb
Expand Up @@ -43,7 +43,7 @@ def authorize_params
end

def raw_info
access_token.options[:mode] = :query
access_token.options[:mode] = :header
@raw_info ||= access_token.get('user').parsed
end

Expand All @@ -59,7 +59,7 @@ def primary_email
# The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response
def emails
return [] unless email_access_allowed?
access_token.options[:mode] = :query
access_token.options[:mode] = :header
@emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed
end

Expand Down
16 changes: 16 additions & 0 deletions spec/omniauth/strategies/github_spec.rb
Expand Up @@ -122,6 +122,12 @@
expect(access_token).to receive(:get).with('user').and_return(response)
expect(subject.raw_info).to eq(parsed_response)
end

it 'should use the header auth mode' do
expect(access_token).to receive(:get).with('user').and_return(response)
subject.raw_info
expect(access_token.options[:mode]).to eq(:header)
end
end

context '#emails' do
Expand All @@ -133,6 +139,16 @@
subject.options['scope'] = 'user'
expect(subject.emails).to eq(parsed_response)
end

it 'should use the header auth mode' do
expect(access_token).to receive(:get).with('user/emails', :headers => {
'Accept' => 'application/vnd.github.v3'
}).and_return(response)

subject.options['scope'] = 'user'
subject.emails
expect(access_token.options[:mode]).to eq(:header)
end
end

context '#info.email' do
Expand Down