-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deps): Remove dependency to sap cloud sdk
- Loading branch information
1 parent
263fbd2
commit de9509f
Showing
4 changed files
with
47 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IncomingMessage } from "http"; | ||
|
||
export function retrieveJwt(req: IncomingMessage): string | undefined { | ||
const header = authHeader(req); | ||
if (validateAuthHeader(header)) { | ||
return header!.split(" ")[1]; | ||
} | ||
} | ||
|
||
function authHeader(req: IncomingMessage): string | undefined { | ||
const entries = Object.entries(req.headers).find(([key]) => key.toLowerCase() === "authorization"); | ||
if (entries) { | ||
const header = entries[1]; | ||
|
||
// Header could be a list of headers | ||
return Array.isArray(header) ? header[0] : header; | ||
} | ||
return undefined; | ||
} | ||
|
||
function validateAuthHeader(header: string | undefined): boolean { | ||
if (typeof header === "undefined") { | ||
console.warn("Authorization header not set."); | ||
return false; | ||
} | ||
|
||
const [authType, token] = header.split(" "); | ||
|
||
if (typeof token === "undefined") { | ||
console.warn("Token in auth header missing."); | ||
return false; | ||
} | ||
|
||
if (authType.toLowerCase() !== "bearer") { | ||
console.warn("Authorization type is not Bearer."); | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters