JavaScript Node.js, SAML- , Node zlib Buffer . , pako ( ).
saml-encode-decoder-js NPM. :
var saml = require('saml');
saml.decodeSamlRedirect(xml, function(err, xml) {
if (!err) {
console.log("Redirect decoded XML", xml);
}
}
saml.decodeSamlPost(xml, function(err, xml) {
if (!err) {
console.log("POST decoded XML", xml);
}
}
NPM . , saml-encoder-decoder-js SAML:
var zlib = require('zlib');
function decodeSamlRedirect(encoded, cb) {
if (encoded == null || encoded == "") {
return cb(new Error('Cannot decode null string'));
}
var deflated = new Buffer(decodeURIComponent(encoded), 'base64');
zlib.inflateRaw(deflated, function (err, inflated) {
if (!err) {
return cb(null, inflated.toString('ascii'));
} else {
return cb(err);
}
});
}
zlib.deflateRaw() zlib.inflateRaw() . deflate() unzip().
If you use SAML POST bindings, then this is really just a shell for using Node Bufferto encode Base64 encoding / decoding, as here:
function decodeSamlPost(encoded, cb) {
if (encoded == null || encoded == "") {
return cb(new Error('Cannot decode null string'));
}
return cb(null, new Buffer(encoded, 'base64').toString('ascii'));
}
source
share