Skip to content

Commit

Permalink
Merge pull request #84 from DazWorrall/query-auth-deprecated
Browse files Browse the repository at this point in the history
Use header auth mode for user and email requests
  • Loading branch information
suprnova32 committed Feb 5, 2020
2 parents 2e77639 + f367321 commit 4aca7b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 4aca7b6

Please sign in to comment.