diff --git a/packages/isomorphic-core/src/imap-connection.js b/packages/isomorphic-core/src/imap-connection.js index 839997108..f1ff3fffe 100644 --- a/packages/isomorphic-core/src/imap-connection.js +++ b/packages/isomorphic-core/src/imap-connection.js @@ -49,7 +49,7 @@ class IMAPConnection extends EventEmitter { if (!this._connectPromise) { this._connectPromise = this._resolveIMAPSettings().then((settings) => { this.resolvedSettings = settings - this._buildUnderlyingConnection(settings) + return this._buildUnderlyingConnection(settings) }); } return this._connectPromise; @@ -64,6 +64,7 @@ class IMAPConnection extends EventEmitter { tls: this._settings.ssl_required, } + // This account uses XOAuth2, and we have the client_id + refresh token if (this._settings.refresh_token) { const xoauthFields = ['client_id', 'client_secret', 'imap_username', 'refresh_token']; if (Object.keys(_.pick(this._settings, xoauthFields)).length !== 4) { @@ -84,6 +85,13 @@ class IMAPConnection extends EventEmitter { }); } + // This account uses XOAuth2, and we have a token given to us by the + // backend, which has the client secret. + if (this._settings.xoauth2) { + delete result.password; + result.xoauth2 = this._settings.xoauth2; + } + return Promise.resolve(result); } diff --git a/packages/local-sync/src/local-api/routes/auth.js b/packages/local-sync/src/local-api/routes/auth.js index ee11fcdbd..bc6f76078 100644 --- a/packages/local-sync/src/local-api/routes/auth.js +++ b/packages/local-sync/src/local-api/routes/auth.js @@ -22,10 +22,8 @@ const imapSmtpSettings = Joi.object().keys({ ssl_required: Joi.boolean().required(), }).required(); -const gmailSettings = Joi.object().keys({ - google_client_id: Joi.string().required(), - google_client_secret: Joi.string().required(), - google_refresh_token: Joi.string().required(), +const resolvedGmailSettings = Joi.object().keys({ + xoauth2: Joi.string().required(), }); const exchangeSettings = Joi.object().keys({ @@ -90,7 +88,7 @@ module.exports = (server) => { email: Joi.string().email().required(), name: Joi.string().required(), provider: Joi.string().valid('imap', 'gmail').required(), - settings: Joi.alternatives().try(imapSmtpSettings, exchangeSettings, gmailSettings), + settings: Joi.alternatives().try(imapSmtpSettings, exchangeSettings, resolvedGmailSettings), }, }, response: { @@ -128,9 +126,7 @@ module.exports = (server) => { ssl_required: true, } connectionCredentials = { - client_id: settings.google_client_id, - client_secret: settings.google_client_secret, - refresh_token: settings.google_refresh_token, + xoauth2: settings.xoauth2, } }