Skip to content

Commit

Permalink
add jwt handler for auth config
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilShahi committed Sep 22, 2022
1 parent 4a246be commit b69d70c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions backend/src/services/authentication-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AuthenticationConfigService {
let sessionMeta: SessionMeta = {
authenticationProvided: false,
authType: authConfig.authType,
authenticationSuccessful: successfulAuth,
} as SessionMeta
requestHeaders.forEach(header => {
switch (authConfig.authType) {
Expand Down Expand Up @@ -95,6 +96,43 @@ export class AuthenticationConfigService {
}
break
case AuthType.JWT:
const jwtHeader = authConfig.headerKey ?? ""
if (header.name.toLowerCase() === jwtHeader.toLowerCase()) {
const { encrypted, tag } = encrypt(
header.value,
encryptionKey,
keypairIv,
)
sessionMeta = {
authenticationProvided: true,
authenticationSuccessful: successfulAuth,
authType: authConfig.authType,
uniqueSession: {
key: encrypted,
iv: keypairIv.toString("base64"),
tag: tag.toString("base64"),
},
}
const decodedPayload = JSON.parse(
Buffer.from(
header.value?.split(".")?.[1] ?? "",
"base64",
)?.toString() || "{}",
)
if (authConfig.jwtUserPath) {
const jwtUser = authConfig.jwtUserPath
.split(".")
.reduce((o, k) => {
return o && o[k]
}, decodedPayload)
if (jwtUser && typeof jwtUser === "string") {
sessionMeta = {
...sessionMeta,
user: jwtUser,
}
}
}
}
break
default:
}
Expand Down

0 comments on commit b69d70c

Please sign in to comment.