From 8d1f8b665501dd27bae941ea8e128597b7e8edea Mon Sep 17 00:00:00 2001 From: riking Date: Tue, 2 Sep 2014 15:06:05 -0700 Subject: [PATCH] Include 'email_verified', + all email data in extra response This allows consumers to check whether or not Github has verified the emails. Manual selection by consumers is also available using the emails array in the `extra` response data. Additionally, a new 'display_email' field is added to `info`, which will always be the email displayed on your GitHub user page. --- lib/omniauth/strategies/github.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/omniauth/strategies/github.rb b/lib/omniauth/strategies/github.rb index 21c824a..9c3e4d4 100644 --- a/lib/omniauth/strategies/github.rb +++ b/lib/omniauth/strategies/github.rb @@ -29,6 +29,8 @@ def authorize_params { 'nickname' => raw_info['login'], 'email' => email, + 'email_verified' => @email_verified || false, + 'display_email' => raw_info['email'], 'name' => raw_info['name'], 'image' => raw_info['avatar_url'], 'urls' => { @@ -39,7 +41,7 @@ def authorize_params end extra do - {:raw_info => raw_info} + {:raw_info => raw_info, :all_emails => emails} end def raw_info @@ -48,12 +50,16 @@ def raw_info end def email - (email_access_allowed?) ? primary_email : raw_info['email'] + (email_access_allowed?) ? primary_email : raw_info['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'] } + if primary && primary['email'] + @email_verified = primary['verified'] + return primary['email'] + end + emails.first && emails.first['email'] end # The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response