Skip to content
Permalink
Browse files

Auto-clear cookies on reauthenticate for gmail and trello #1018

  • Loading branch information...
Thomas101 committed May 9, 2019
1 parent d828406 commit 6c7529ba60711dfdb10f8a4d0ecef298aafb267e
@@ -1 +1 @@
{"usesAuthWindow":">= 4.9.4"}
{"usesAuthWindow":">= 4.9.4","clearCookiesOnReauthenticate":true}
@@ -1 +1 @@
{"version":6,"name":"gmail"}
{"version":7,"name":"gmail"}
@@ -1 +1 @@
{"usesAuthWindow":">= 4.9.4"}
{"usesAuthWindow":">= 4.9.4","clearCookiesOnReauthenticate":true}
@@ -1 +1 @@
{"version":2,"name":"trello"}
{"version":3,"name":"trello"}
@@ -1,4 +1,4 @@
import { app, ipcMain, webContents } from 'electron'
import { app, ipcMain, webContents, session } from 'electron'
import IEngineRuntime from './IEngineRuntime'
import IEngineStoreConnections from './IEngineStoreConnections'
import IEngineLoader from './IEngineLoader'
@@ -10,6 +10,7 @@ import {
IENGINE_ALIASES,
IENGINE_ALIAS_TO_TYPE
} from 'shared/IEngine/IEngineTypes'
import IENGINE_AUTH_MODES from 'shared/IEngine/IEngineAuthModes'

const privRuntimes = Symbol('privRuntimes')
const privStoreConnections = Symbol('privStoreConnections')
@@ -185,18 +186,31 @@ class IEngine {
return returnError(`Failed to load adaptor for iengine "${iengineAlias}"`)
}

// Run the task
if (this[privAuthRuntime].adaptorUsesAuthWindow(adaptor)) {
this[privAuthRuntime].startAuthWindow(engineType, authConfig.partitionId)
.then(
(res) => returnSuccess(res),
(ex) => returnError(ex)
)
return
}

// No specific action found - just return to sender
return returnSuccess({})
// Run the tasks
Promise.resolve()
.then(() => {
if (authConfig.authMode === IENGINE_AUTH_MODES.REAUTHENTICATE) {
if (this[privAuthRuntime].adaptorClearsCookiesOnReauthenticate(adaptor)) {
const ses = session.fromPartition(authConfig.partitionId)
return Promise.resolve()
.then(() => { return new Promise((resolve) => { ses.clearStorageData(resolve) }) })
.then(() => { return new Promise((resolve) => { ses.clearCache(resolve) }) })
.catch((ex) => Promise.resolve()) // gobble
}
}
return Promise.resolve()
})
.then(() => {
if (this[privAuthRuntime].adaptorUsesAuthWindow(adaptor)) {
return this[privAuthRuntime].startAuthWindow(engineType, authConfig.partitionId, authConfig.authMode)
} else {
return Promise.resolve()
}
})
.then(
(res) => returnSuccess(res),
(ex) => returnError(ex)
)
}
}

@@ -22,9 +22,10 @@ class IEngineAuthRuntime {
* Starts a new service auth in a window
* @param engineType: the iengine type
* @param partitionId: the id of the partition to use
* @param authMode: the auth mode
* @return promise
*/
startAuthWindow (engineType, partitionId) {
startAuthWindow (engineType, partitionId, authMode) {
return new Promise((resolve, reject) => {
if (this[privTask]) {
this[privTask].forceFinish()
@@ -65,6 +66,14 @@ class IEngineAuthRuntime {
adaptorUsesAuthWindow (adaptor) {
return adaptor.usesAuthWindow === true || semver.satisfies(pkg.version, adaptor.usesAuthWindow)
}

/**
* @param adaptor: the adaptor to check
* @return true if the adaptor requires a cookie clear on reauth
*/
adaptorClearsCookiesOnReauthenticate (adaptor) {
return adaptor.clearCookiesOnReauthenticate === true || semver.satisfies(pkg.version, adaptor.clearCookiesOnReauthenticate)
}
}

export default IEngineAuthRuntime
@@ -34,6 +34,7 @@ import CoreACAuth from 'shared/Models/ACAccounts/CoreACAuth'
import ACProvisoService from 'shared/Models/ACAccounts/ACProvisoService'
import ACCOUNT_WARNING_TYPES from 'shared/Models/ACAccounts/AccountWarningTypes'
import ServiceFactory from 'shared/Models/ACAccounts/ServiceFactory'
import IENGINE_AUTH_MODES from 'shared/IEngine/IEngineAuthModes'

const AUTH_MODES = Object.freeze({
TEMPLATE_CREATE: 'TEMPLATE_CREATE',
@@ -448,6 +449,7 @@ class AccountStore extends RendererAccountStore {
window.location.hash = `/mailbox_wizard/${template.templateType}/_/1/${mailboxId}`
return this._iengineAuthServicePromise(serviceType, {
partitionId: `persist:${mailboxId}`,
authMode: IENGINE_AUTH_MODES.TEMPLATE_CREATE,
context: {
mailboxId: mailboxId,
template: template.cloneData()
@@ -697,6 +699,7 @@ class AccountStore extends RendererAccountStore {
window.location.hash = `/mailbox_attach_wizard/${attachTarget}/${serviceType}/${accessMode}/1`
return this._iengineAuthServicePromise(serviceType, {
partitionId: `persist:${attachTarget}`,
authMode: IENGINE_AUTH_MODES.ATTACH,
context: {
mailboxId: attachTarget,
authId: authId
@@ -974,6 +977,7 @@ class AccountStore extends RendererAccountStore {
window.location.hash = '/mailbox/reauthenticating'
return this._iengineAuthServicePromise(service.type, {
partitionId: service.partitionId,
authMode: IENGINE_AUTH_MODES.REAUTHENTICATE,
context: {
mailboxId: service.parentId,
authId: CoreACAuth.compositeIdFromService(service),
@@ -0,0 +1,7 @@
const IENGINE_AUTH_MODES = Object.freeze({
TEMPLATE_CREATE: 'TEMPLATE_CREATE',
REAUTHENTICATE: 'REAUTHENTICATE',
ATTACH: 'ATTACH'
})

export default IENGINE_AUTH_MODES

0 comments on commit 6c7529b

Please sign in to comment.
You can’t perform that action at this time.