[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
This commit is contained in:
Halla Moore 2017-01-14 17:24:13 -08:00
parent ae981af646
commit c5453ca21b

View file

@ -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),
},
},