diff --git a/package.json b/package.json index 45ddd91c..aec0dd4f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "jsonwebtoken": "^8.5.1", "jwt-decode": "^2.2.0", "keycloak-admin": "^1.13.0", - "keycloak-connect": "git+https://github.com/sunbird-cb/keycloak-nodejs-connect.git#release-2.5.0", + "keycloak-connect": "git+https://github.com/sunbird-cb/keycloak-nodejs-connect.git#release-2.6.0", "lodash": "^4.17.21", "morgan": "^1.9.1", "node-xlsx": "^0.15.0", diff --git a/src/server.ts b/src/server.ts index 361566f8..88bf2999 100644 --- a/src/server.ts +++ b/src/server.ts @@ -182,14 +182,12 @@ export class Server { private resetCookies() { this.app.use('/reset', (_req, res) => { logInfo('CLEARING RES COOKIES') - res.clearCookie('connect.sid', { path: '/' }) - const host = _req.get('host') - let redirectUrl = '/public/logout' - logInfo('Reset Cookies... received host value ' + host) - if (host === `${CONSTANTS.KARMAYOGI_PORTAL_HOST}`) { - redirectUrl = '/public/home' + res.status(200).clearCookie('connect.sid', { path: '/' }) + if (_req.session) { + _req.session.destroy(() => { + res.redirect('/apis/logout') + }) } - res.redirect(redirectUrl) }) } diff --git a/src/utils/apiWhiteList.ts b/src/utils/apiWhiteList.ts index 59522138..76f34c6b 100644 --- a/src/utils/apiWhiteList.ts +++ b/src/utils/apiWhiteList.ts @@ -35,6 +35,7 @@ const checkIsStaticRoute = (REQ_URL: any) => { '/content-plugins/', '/editors/', '/public/', + '/logout', '/v1/form/read', ] // tslint:disable-next-line: no-any diff --git a/src/utils/custom-keycloak.ts b/src/utils/custom-keycloak.ts index 25c918e5..3d2c0808 100644 --- a/src/utils/custom-keycloak.ts +++ b/src/utils/custom-keycloak.ts @@ -31,7 +31,7 @@ export class CustomKeycloak { const middleware = composable( keycloak.middleware({ admin: '/callback', - logout: '/reset', + logout: '/logout', }) ) middleware(req, res, next) @@ -83,6 +83,18 @@ export class CustomKeycloak { }) } + // tslint:disable-next-line: no-any + deauthenticatedNew = (reqObj: any) => { + delete reqObj.session.userRoles + delete reqObj.session.userId + delete reqObj.session.keycloakClientId + delete reqObj.session.keycloakClientSecret + if (reqObj.session) { + reqObj.session.destroy() + } + logInfo(`${process.pid}: User Deauthenticated New`) + } + // tslint:disable-next-line: no-any deauthenticated = (reqObj: any) => { const keyCloakPropertyName = 'keycloak-token' @@ -173,7 +185,7 @@ export class CustomKeycloak { getKeycloakConfig(url, realm) ) keycloak.authenticated = this.authenticated - keycloak.deauthenticated = this.deauthenticated + keycloak.deauthenticated = this.deauthenticatedNew return keycloak } }