Skip to content

Commit 6b497a8

Browse files
authored
Merge pull request omniauth#79 from davebrace/include-token-scope-in-extra
Include the received access token's scope in the 'extra' hash
2 parents 4f3706a + 1b3a35c commit 6b497a8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/omniauth/strategies/github.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def authorize_params
3939
end
4040

4141
extra do
42-
{:raw_info => raw_info, :all_emails => emails}
42+
{:raw_info => raw_info, :all_emails => emails, :scope => scope }
4343
end
4444

4545
def raw_info
@@ -51,6 +51,10 @@ def email
5151
(email_access_allowed?) ? primary_email : raw_info['email']
5252
end
5353

54+
def scope
55+
access_token['scope']
56+
end
57+
5458
def primary_email
5559
primary = emails.find{ |i| i['primary'] && i['verified'] }
5660
primary && primary['email'] || nil

spec/omniauth/strategies/github_spec.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe OmniAuth::Strategies::GitHub do
4-
let(:access_token) { instance_double('AccessToken', :options => {}) }
4+
let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
55
let(:parsed_response) { instance_double('ParsedResponse') }
66
let(:response) { instance_double('Response', :parsed => parsed_response) }
77

@@ -166,6 +166,12 @@
166166
end
167167
end
168168

169+
context '#extra.scope' do
170+
it 'returns the scope on the returned access_token' do
171+
expect(subject.scope).to eq('user')
172+
end
173+
end
174+
169175
describe '#callback_url' do
170176
it 'is a combination of host, script name, and callback path' do
171177
allow(subject).to receive(:full_host).and_return('https://example.com')

0 commit comments

Comments
 (0)