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

Include the received access token's scope in the 'extra' hash #79

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
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 @@ -150,6 +150,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