feat(JWT Node): New node (#9005)

Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Michael Kret
2024-04-10 13:16:48 +03:00
committed by GitHub
parent 9403657e46
commit 0a9f6b3de8
12 changed files with 1088 additions and 6 deletions

View File

@@ -223,14 +223,17 @@ export const keysToLowercase = <T>(headers: T) => {
* @param privateKey - The private key to format.
* @returns The formatted private key.
*/
export function formatPrivateKey(privateKey: string): string {
export function formatPrivateKey(privateKey: string, keyIsPublic = false): string {
let regex = /(PRIVATE KEY|CERTIFICATE)/;
if (keyIsPublic) {
regex = /(PUBLIC KEY)/;
}
if (!privateKey || /\n/.test(privateKey)) {
return privateKey;
}
let formattedPrivateKey = '';
const parts = privateKey.split('-----').filter((item) => item !== '');
parts.forEach((part) => {
const regex = /(PRIVATE KEY|CERTIFICATE)/;
if (regex.test(part)) {
formattedPrivateKey += `-----${part}-----`;
} else {