Prefer to use primary email for new user creation over other available emails
This commit is contained in:
parent
19a93b0e95
commit
c5d26992d4
|
@ -47,6 +47,8 @@ class Auth::GithubAuthenticator < Auth::Authenticator
|
||||||
# Potentially use *any* of the emails from GitHub to find a match or
|
# Potentially use *any* of the emails from GitHub to find a match or
|
||||||
# register a new user, with preference given to the primary email.
|
# register a new user, with preference given to the primary email.
|
||||||
all_emails = Array.new(auth_token[:extra][:all_emails])
|
all_emails = Array.new(auth_token[:extra][:all_emails])
|
||||||
|
primary = all_emails.detect { |email| email[:primary] && email[:verified] }
|
||||||
|
all_emails.unshift(primary) if primary.present?
|
||||||
|
|
||||||
# Only consider verified emails to match an existing user. We don't want
|
# Only consider verified emails to match an existing user. We don't want
|
||||||
# someone to be able to create a GitHub account with an unverified email
|
# someone to be able to create a GitHub account with an unverified email
|
||||||
|
|
|
@ -57,6 +57,32 @@ describe Auth::GithubAuthenticator do
|
||||||
expect(result.email_valid).to eq(true)
|
expect(result.email_valid).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should use primary email for new user creation over other available emails' do
|
||||||
|
hash = {
|
||||||
|
extra: {
|
||||||
|
all_emails: [{
|
||||||
|
email: "bob@example.com",
|
||||||
|
primary: false,
|
||||||
|
verified: true,
|
||||||
|
}, {
|
||||||
|
email: "john@example.com",
|
||||||
|
primary: true,
|
||||||
|
verified: true,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
info: {
|
||||||
|
email: "john@example.com",
|
||||||
|
nickname: "john",
|
||||||
|
name: "John Bob",
|
||||||
|
},
|
||||||
|
uid: "100"
|
||||||
|
}
|
||||||
|
|
||||||
|
result = authenticator.after_authenticate(hash)
|
||||||
|
|
||||||
|
expect(result.email).to eq("john@example.com")
|
||||||
|
end
|
||||||
|
|
||||||
it 'will not authenticate for already existing users with an unverified email' do
|
it 'will not authenticate for already existing users with an unverified email' do
|
||||||
hash = {
|
hash = {
|
||||||
extra: {
|
extra: {
|
||||||
|
|
Loading…
Reference in New Issue