Skip to content

Instantly share code, notes, and snippets.

@L1fescape
Last active May 30, 2022 08:38
Show Gist options
  • Save L1fescape/06398c8c5be34ec85f35ca8c7154146c to your computer and use it in GitHub Desktop.
Save L1fescape/06398c8c5be34ec85f35ca8c7154146c to your computer and use it in GitHub Desktop.
simple saml decoder
{
"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"
}
}
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