Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/omniauth/strategies/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def authorize_params
info do
{
'nickname' => raw_info['login'],
'email' => email,
'email' => primary_email,
'name' => raw_info['name'],
'image' => raw_info['avatar_url'],
'urls' => {
Expand All @@ -39,7 +39,7 @@ def authorize_params
end

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

def raw_info
Expand All @@ -52,8 +52,8 @@ def email
end

def primary_email
primary = emails.find{|i| i['primary'] }
primary && primary['email'] || emails.first && emails.first['email']
primary = emails.find{ |i| i['primary'] && i['verified'] }
primary && primary['email'] || nil
end

# The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response
Expand Down
8 changes: 4 additions & 4 deletions spec/omniauth/strategies/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,26 @@
subject.email.should be_nil
end

it "should return the primary email if there is no raw_info and email access is allowed" do
it "should not return the primary email if there is no raw_info and email access is allowed" do
emails = [
{ 'email' => 'secondary@example.com', 'primary' => false },
{ 'email' => 'primary@example.com', 'primary' => true }
]
subject.stub!(:raw_info).and_return({})
subject.options['scope'] = 'user'
subject.stub!(:emails).and_return(emails)
subject.email.should eq('primary@example.com')
subject.email.should eq(nil)
end

it "should return the first email if there is no raw_info and email access is allowed" do
it "should not return the first email if there is no raw_info and email access is allowed" do
emails = [
{ 'email' => 'first@example.com', 'primary' => false },
{ 'email' => 'second@example.com', 'primary' => false }
]
subject.stub!(:raw_info).and_return({})
subject.options['scope'] = 'user'
subject.stub!(:emails).and_return(emails)
subject.email.should eq('first@example.com')
subject.email.should eq(nil)
end
end

Expand Down