n8n
Version:
n8n Workflow Automation Tool
27 lines • 977 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isJweToken = isJweToken;
exports.decryptJweToken = decryptJweToken;
exports.decryptJweTokenData = decryptJweTokenData;
const jose_1 = require("jose");
const JWE_SEGMENT_COUNT = 5;
function isJweToken(token) {
if (typeof token !== 'string' || token.length === 0)
return false;
return token.split('.').length === JWE_SEGMENT_COUNT;
}
async function decryptJweToken(token, privateKey) {
const { plaintext } = await (0, jose_1.compactDecrypt)(token, privateKey);
return new TextDecoder().decode(plaintext);
}
async function decryptJweTokenData(data, privateKey) {
const result = { ...data };
for (const field of ['access_token', 'id_token']) {
const value = result[field];
if (isJweToken(value)) {
result[field] = await decryptJweToken(value, privateKey);
}
}
return result;
}
//# sourceMappingURL=oauth-jwe.utils.js.map