Last active
May 30, 2022 08:38
-
-
Save L1fescape/06398c8c5be34ec85f35ca8c7154146c to your computer and use it in GitHub Desktop.
simple saml decoder
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
{ | |
"name": "saml-decode", | |
"version": "1.0.0", | |
"description": "", | |
"main": "saml-decode.js", | |
"scripts": { | |
"start": "node saml-decode.js" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"saml-encoder-decoder-js": "^1.0.1", | |
"xml2json": "^0.12.0" | |
} | |
} |
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
const fs = require('fs/promises') | |
const SAML = require('saml-encoder-decoder-js') | |
const xmlParser = require('xml2json') | |
const payloadFilename = process.env.FILE || 'input.txt' | |
const decodeSaml = async (token) => ( | |
new Promise(accept => { | |
SAML.decodeSamlPost(token, function(err, xml) { | |
if (err) { | |
console.error(err) | |
throw new Error(err) | |
} | |
accept(xml) | |
}) | |
}) | |
) | |
async function decode() { | |
const data = await fs.readFile(payloadFilename, { encoding: 'utf8' }) | |
const xml = await decodeSaml(data).catch(e => process.exit(0)) | |
const json = xmlParser.toJson(xml, { | |
object: true, | |
sanitize: true, | |
trim: true | |
}) | |
console.log(json["samlp:Response"]) | |
} | |
(async () => await decode())() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment