Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
FIX: don't show users logging in with secondary email sign up form
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Aug 29, 2018
1 parent 211e171 commit 2d0840d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/mozilla_iam/authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def after_authenticate(auth_token)

result.email = email = payload['email']
result.email_valid = email_valid = payload['email_verified']
user = UserEmail.where(email: email, primary: true).first&.user if email_valid
result.user = user
result.user = user = User.find_by_email(email) if email_valid
if Array(user&.secondary_emails).include? email
raise "user #{user.id} attempted to log in with secondary email #{email}"
end
result.name = payload['name']
uid = payload['sub']
result.extra_data = { uid: uid }
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# name: mozilla-iam
# about: A plugin to integrate Discourse with Mozilla's Identity and Access Management (IAM) system
# version: 0.2.2
# version: 0.2.3
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-mozilla-iam

Expand Down
4 changes: 2 additions & 2 deletions spec/components/mozilla_iam/authenticator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
expect(result.failed).to eq(true)
end

it 'will not log in with an id_token with an unverified email' do
it 'will verify email in sign up form with an id_token with an unverified email' do
user = Fabricate(:user)
id_token = create_id_token(user, { email_verified: false })
result = authenticate_with_id_token(id_token)
Expand All @@ -123,7 +123,7 @@
id_token = create_id_token(user, { email: user.secondary_emails.first })
result = authenticate_with_id_token(id_token)

expect(result.user).to eq(nil)
expect(result.failed).to eq true
end
end

Expand Down

0 comments on commit 2d0840d

Please sign in to comment.