mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-08 13:44:53 +08:00
Gmail auth: resolved settings tests
This commit is contained in:
parent
30a94a6c9b
commit
e7386ff4ae
2 changed files with 13 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue