Skip to content

Commit

Permalink
Merged changes from cbrelease-4.8.13 w.r.t. KAR-202
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed May 16, 2024
2 parents bbdc056 + 544cb00 commit 96dfbad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 5 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/apiWhiteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const checkIsStaticRoute = (REQ_URL: any) => {
'/content-plugins/',
'/editors/',
'/public/',
'/logout',
'/v1/form/read',
]
// tslint:disable-next-line: no-any
Expand Down
16 changes: 14 additions & 2 deletions src/utils/custom-keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CustomKeycloak {
const middleware = composable(
keycloak.middleware({
admin: '/callback',
logout: '/reset',
logout: '/logout',
})
)
middleware(req, res, next)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -173,7 +185,7 @@ export class CustomKeycloak {
getKeycloakConfig(url, realm)
)
keycloak.authenticated = this.authenticated
keycloak.deauthenticated = this.deauthenticated
keycloak.deauthenticated = this.deauthenticatedNew
return keycloak
}
}

0 comments on commit 96dfbad

Please sign in to comment.