fix: Lowercase email from auth providers to match any outstanding invites (#3369)

* fix: Lowercase email from auth providers to match any outstanding invites

* fix
This commit is contained in:
Tom Moor
2022-04-12 21:31:55 -07:00
committed by GitHub
parent 1de732c82a
commit d3ecab3489
5 changed files with 8 additions and 10 deletions

View File

@@ -187,12 +187,13 @@ describe("userCreator", () => {
const team = await buildTeam(); const team = await buildTeam();
const invite = await buildInvite({ const invite = await buildInvite({
teamId: team.id, teamId: team.id,
email: "invite@example.com",
}); });
const authenticationProviders = await team.$get("authenticationProviders"); const authenticationProviders = await team.$get("authenticationProviders");
const authenticationProvider = authenticationProviders[0]; const authenticationProvider = authenticationProviders[0];
const result = await userCreator({ const result = await userCreator({
name: invite.name, name: invite.name,
email: invite.email!, email: "invite@ExamPle.com",
teamId: invite.teamId, teamId: invite.teamId,
ip, ip,
authentication: { authentication: {

View File

@@ -86,7 +86,9 @@ export default async function userCreator({
// shell user record. // shell user record.
const invite = await User.findOne({ const invite = await User.findOne({
where: { where: {
email, // Email from auth providers may be capitalized and we should respect that
// however any existing invites will always be lowercased.
email: email.toLowerCase(),
teamId, teamId,
lastActiveAt: { lastActiveAt: {
[Op.is]: null, [Op.is]: null,

View File

@@ -40,7 +40,7 @@ if (AZURE_CLIENT_ID) {
try { try {
// see docs for what the fields in profile represent here: // see docs for what the fields in profile represent here:
// https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens // https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens
const profile = jwt.decode(params.id_token); const profile = jwt.decode(params.id_token) as jwt.JwtPayload;
// Load the users profile from the Microsoft Graph API // Load the users profile from the Microsoft Graph API
// https://docs.microsoft.com/en-us/graph/api/resources/users?view=graph-rest-1.0 // https://docs.microsoft.com/en-us/graph/api/resources/users?view=graph-rest-1.0
@@ -69,7 +69,6 @@ if (AZURE_CLIENT_ID) {
} }
const organization = organizationResponse.value[0]; const organization = organizationResponse.value[0];
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
const email = profile.email || profileResponse.mail; const email = profile.email || profileResponse.mail;
if (!email) { if (!email) {
@@ -89,19 +88,15 @@ if (AZURE_CLIENT_ID) {
subdomain, subdomain,
}, },
user: { user: {
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
name: profile.name, name: profile.name,
email, email,
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
avatarUrl: profile.picture, avatarUrl: profile.picture,
}, },
authenticationProvider: { authenticationProvider: {
name: providerName, name: providerName,
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
providerId: profile.tid, providerId: profile.tid,
}, },
authentication: { authentication: {
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
providerId: profile.oid, providerId: profile.oid,
accessToken, accessToken,
refreshToken, refreshToken,

View File

@@ -61,8 +61,8 @@ if (GOOGLE_CLIENT_ID) {
subdomain, subdomain,
}, },
user: { user: {
name: profile.displayName,
email: profile.email, email: profile.email,
name: profile.displayName,
avatarUrl: profile.picture, avatarUrl: profile.picture,
}, },
authenticationProvider: { authenticationProvider: {

View File

@@ -76,7 +76,7 @@ if (OIDC_CLIENT_ID) {
); );
} }
const parts = profile.email.split("@"); const parts = profile.email.toLowerCase().split("@");
const domain = parts.length && parts[1]; const domain = parts.length && parts[1];
if (!domain) { if (!domain) {