Skip to content

Commit

Permalink
Merge pull request #79 from davebrace/include-token-scope-in-extra
Browse files Browse the repository at this point in the history
Include the received access token's scope in the 'extra' hash
  • Loading branch information
suprnova32 committed Feb 5, 2020
2 parents 4f3706a + 1b3a35c commit 6b497a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/omniauth/strategies/github.rb
Expand Up @@ -39,7 +39,7 @@ def authorize_params
end

extra do
{:raw_info => raw_info, :all_emails => emails}
{:raw_info => raw_info, :all_emails => emails, :scope => scope }
end

def raw_info
Expand All @@ -51,6 +51,10 @@ def email
(email_access_allowed?) ? primary_email : raw_info['email']
end

def scope
access_token['scope']
end

def primary_email
primary = emails.find{ |i| i['primary'] && i['verified'] }
primary && primary['email'] || nil
Expand Down
8 changes: 7 additions & 1 deletion spec/omniauth/strategies/github_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe OmniAuth::Strategies::GitHub do
let(:access_token) { instance_double('AccessToken', :options => {}) }
let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
let(:parsed_response) { instance_double('ParsedResponse') }
let(:response) { instance_double('Response', :parsed => parsed_response) }

Expand Down Expand Up @@ -166,6 +166,12 @@
end
end

context '#extra.scope' do
it 'returns the scope on the returned access_token' do
expect(subject.scope).to eq('user')
end
end

describe '#callback_url' do
it 'is a combination of host, script name, and callback path' do
allow(subject).to receive(:full_host).and_return('https://example.com')
Expand Down

0 comments on commit 6b497a8

Please sign in to comment.