[iso-core] Use SUPPORTED_PROVIDERS in Account.smtpConfig()

Summary:
Consolidating provider checks to use the same source of truth.
Fixes send issues with some provider types.

Test Plan: tested locally

Reviewers: tomasz

Reviewed By: tomasz

Differential Revision: https://phab.nylas.com/D3694
This commit is contained in:
Halla Moore 2017-01-15 14:30:48 -08:00
parent d91992cdb8
commit 6312c3a06b
2 changed files with 6 additions and 4 deletions

View file

@ -91,6 +91,7 @@ function credentialsForProvider({provider, settings, email}) {
}
module.exports = {
SUPPORTED_PROVIDERS,
imapAuthRouteConfig() {
return {
description: 'Authenticates a new account.',

View file

@ -1,5 +1,6 @@
const crypto = require('crypto');
const {JSONColumn, JSONArrayColumn} = require('../database-types');
const {SUPPORTED_PROVIDERS} = require('../auth-helpers');
const {DB_ENCRYPTION_ALGORITHM, DB_ENCRYPTION_PASSWORD} = process.env;
@ -126,14 +127,14 @@ module.exports = (sequelize, Sequelize) => {
secure: ssl_required,
}
}
if (this.provider === "imap" || this.provider === "office365") {
const {smtp_username, smtp_password} = this.decryptedCredentials();
config.auth = { user: smtp_username, pass: smtp_password}
} else if (this.provider === 'gmail') {
if (this.provider === 'gmail') {
const {xoauth2} = this.decryptedCredentials();
const {imap_username} = this.connectionSettings;
const token = this.bearerToken(xoauth2);
config.auth = { user: imap_username, xoauth2: token }
} else if (SUPPORTED_PROVIDERS.has(this.provider)) {
const {smtp_username, smtp_password} = this.decryptedCredentials();
config.auth = { user: smtp_username, pass: smtp_password}
} else {
throw new Error(`${this.provider} not yet supported`)
}