Skip to content

Commit

Permalink
fix(outlook): Fixed Outlook OAuth2 connection
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 14, 2024
1 parent e2e72f0 commit 920aa20
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
11 changes: 5 additions & 6 deletions lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ class Account {
result.path = '*';
}

if (result.imap && !result.imapIndexer) {
result.imapIndexer = 'full';
}

if (typeof result.account === 'undefined') {
result.account = null;
}
Expand Down Expand Up @@ -738,15 +734,18 @@ class Account {
throw error;
}

let oauth2App;
if (accountData.oauth2 && accountData.oauth2.provider) {
// check if this OAuth2 provider exists
let oauth2App = await oauth2Apps.get(accountData.oauth2.provider);
oauth2App = await oauth2Apps.get(accountData.oauth2.provider);
if (!oauth2App) {
let message = 'Invalid or missing OAuth2 provider';
let error = Boom.boomify(new Error(message), { statusCode: 400 });
throw error;
}
} else if (accountData.imap && !accountData.imapIndexer) {
}

if (!accountData.imapIndexer && (accountData.imap || (oauth2App && (!oauth2App.baseScopes || oauth2App.baseScopes === 'imap')))) {
accountData.imapIndexer = (await settings.get('imapIndexer')) || 'full';
}

Expand Down
1 change: 1 addition & 0 deletions lib/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ const accountSchemas = {
.description(
'Sets the account-specific IMAP indexing method. Choose "full" to build a complete index that tracks deleted and updated emails, or "fast" to only detect newly received emails. Defaults to global setting.'
)
.label('IMAPIndexer')
};

const googleProjectIdSchema = Joi.string().trim().allow('', false, null).max(256).example('project-name-425411').description('Google Cloud Project ID');
Expand Down
26 changes: 20 additions & 6 deletions workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ const init = async () => {

let profileRes;
try {
profileRes = await oAuth2Client.request(r.access_token, `${oAuth2Client.apiBase}/me`);
profileRes = await oAuth2Client.request(r.access_token, `${oAuth2Client.apiBase}/v1.0/me`);
} catch (err) {
let response = err.oauthRequest && err.oauthRequest.response;
if (response && response.error) {
Expand Down Expand Up @@ -3372,14 +3372,16 @@ const init = async () => {
result[key] = result[key] || null;
}

let oauth2App;
if (accountData.oauth2 && accountData.oauth2.provider) {
let app = await oauth2Apps.get(accountData.oauth2.provider);
oauth2App = await oauth2Apps.get(accountData.oauth2.provider);

if (app) {
result.type = app.provider;
if (app.id !== app.provider) {
result.app = app.id;
if (oauth2App) {
result.type = oauth2App.provider;
if (oauth2App.id !== oauth2App.provider) {
result.app = oauth2App.id;
}
result.baseScopes = oauth2App.baseScope || 'imap';
} else {
result.type = 'oauth2';
}
Expand All @@ -3389,6 +3391,10 @@ const init = async () => {
result.type = 'sending';
}

if ((accountData.imap || (oauth2App && (!oauth2App.baseScopes || oauth2App.baseScopes === 'imap'))) && !result.imapIndexer) {
result.imapIndexer = 'full';
}

if (accountData.sync) {
result.syncTime = accountData.sync;
}
Expand Down Expand Up @@ -3466,6 +3472,8 @@ const init = async () => {

path: accountPathSchema.example(['*']).label('AccountPath'),

imapIndexer: accountSchemas.imapIndexer,

subconnections: accountSchemas.subconnections,

webhooks: Joi.string()
Expand Down Expand Up @@ -3513,6 +3521,12 @@ const init = async () => {

type: AccountTypeSchema,
app: Joi.string().max(256).example('AAABhaBPHscAAAAH').description('OAuth2 application ID'),
baseScopes: Joi.string()
.empty('')
.trim()
.valid(...['imap', 'api', 'pubsub'])
.example('imap')
.description('OAuth2 Base Scopes'),

counters: accountCountersSchema,

Expand Down

0 comments on commit 920aa20

Please sign in to comment.