-
Notifications
You must be signed in to change notification settings - Fork 2
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
Reject login when external oauth login matches a different account #34
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,12 @@ export async function ExternalServiceCallback( | |
// If `user` exists, the user has already logged in with this service and is good-to-go | ||
let user = await User.findOne({ [`services.${serviceName}.id`]: id }); | ||
|
||
// Ensure that the oauth method used is linked to the user with the same email address that is entered | ||
if (session.email && user && session.email !== user.email) { | ||
done(null, false, { message: "Login method is linked to another email. Please try again with a different email address." }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is kind of confusing imo. Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding to this, users will be confused by this if we aren't really clear. So it would be good to include the original email the user entered in the error message to. As in, if I enter [email protected] on the initial login screen, then choose a Google account with the email [email protected], the error message might show, "The Google account you signed in with ([email protected]) has a different email than what you originally entered ([email protected]). Please ensure your email address and the account you select have the same email address. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone uses their gt email, [email protected], but chooses to sign in with google ([email protected]), and on the first screen they enter their google email, how should the error message read? |
||
return; | ||
} | ||
|
||
if (session && session.email && session.firstName && session.lastName) { | ||
let signupEmail = session.email.trim().toLowerCase(); | ||
// Only create / modify user account if email and name exist on the session (set by login page) | ||
|
@@ -36,18 +42,19 @@ export async function ExternalServiceCallback( | |
if (!user.services) { | ||
user.services = {}; | ||
} | ||
|
||
if (!user.services[serviceName]) { | ||
user.services[serviceName] = { | ||
id, | ||
email: serviceEmail, | ||
username | ||
}; | ||
} | ||
|
||
try { | ||
user.markModified("services"); | ||
await user.save(); | ||
} | ||
catch (err) { | ||
} catch (err) { | ||
done(err); | ||
return; | ||
} | ||
|
@@ -81,7 +88,7 @@ export async function ExternalServiceCallback( | |
} | ||
|
||
if (!user) { | ||
done(null, false, { "message": "Could not match login to existing account" }); | ||
done(null, false, { message: "Could not match login to an existing account. Please try again with a different login method." }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kinda picky but this can also be triggered by someone choosing the wrong account in the account picker (i.e. for Google which allows multiple user accounts to be logged in) but if there isn't a Ground Truth account with that other account. So I'd say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, if the third-party IdP email doesn't correspond to the email they entered originally, we should:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if picking 3rd party IdPs directly is an option anymore, since there are so many accounts whose 3rd party IdP email doesn't match their main email address on their account, so it wouldn't work. |
||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure we're using the trimmed and lowercased email for all comparisons.