From c5453ca21b70590b72dde95308825950ecd0601b Mon Sep 17 00:00:00 2001 From: Halla Moore Date: Sat, 14 Jan 2017 17:24:13 -0800 Subject: [PATCH] [iso-core] Let auth methods accept all supported providers Summary: Treat any that aren't gmail or office365 as standard imap Test Plan: manual Reviewers: juan, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3686 --- packages/isomorphic-core/src/auth-helpers.js | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/isomorphic-core/src/auth-helpers.js b/packages/isomorphic-core/src/auth-helpers.js index 4fbff45fc..0a4598767 100644 --- a/packages/isomorphic-core/src/auth-helpers.js +++ b/packages/isomorphic-core/src/auth-helpers.js @@ -35,6 +35,10 @@ const USER_ERRORS = { IMAP_RETRY: "We were unable to reach your mail provider. Please try again.", } +const SUPPORTED_PROVIDERS = new Set( + ['gmail', 'office365', 'imap', 'icloud', 'yahoo', 'fastmail'] +); + function credentialsForProvider({provider, settings, email}) { if (provider === "gmail") { const connectionSettings = { @@ -51,17 +55,6 @@ function credentialsForProvider({provider, settings, email}) { expiry_date: settings.expiry_date, } return {connectionSettings, connectionCredentials} - } else if (provider === "imap") { - const connectionSettings = _.pick(settings, [ - 'imap_host', 'imap_port', - 'smtp_host', 'smtp_port', - 'ssl_required', 'smtp_custom_config', - ]); - const connectionCredentials = _.pick(settings, [ - 'imap_username', 'imap_password', - 'smtp_username', 'smtp_password', - ]); - return {connectionSettings, connectionCredentials} } else if (provider === "office365") { const connectionSettings = { imap_host: 'outlook.office365.com', @@ -74,6 +67,7 @@ function credentialsForProvider({provider, settings, email}) { tls: {ciphers: 'SSLv3'}, }, } + const connectionCredentials = { imap_username: email, imap_password: settings.password, @@ -81,6 +75,17 @@ function credentialsForProvider({provider, settings, email}) { smtp_password: settings.password, } return {connectionSettings, connectionCredentials} + } else if (SUPPORTED_PROVIDERS.has(provider)) { + const connectionSettings = _.pick(settings, [ + 'imap_host', 'imap_port', + 'smtp_host', 'smtp_port', + 'ssl_required', 'smtp_custom_config', + ]); + const connectionCredentials = _.pick(settings, [ + 'imap_username', 'imap_password', + 'smtp_username', 'smtp_password', + ]); + return {connectionSettings, connectionCredentials} } throw new Error(`Invalid provider: ${provider}`) } @@ -95,7 +100,7 @@ module.exports = { payload: { email: Joi.string().email().required(), name: Joi.string().required(), - provider: Joi.string().valid('imap', 'gmail', 'office365').required(), + provider: Joi.string().valid(...SUPPORTED_PROVIDERS).required(), settings: Joi.alternatives().try(imapSmtpSettings, office365Settings, resolvedGmailSettings), }, },