Let's assume I have the following in NodeJS:
import {
gzip
} from "node-gzip";
const samlToken = fs.readFileSync(
"./localDevToken.txt",
"utf8",
);
const bufferSamlToken = Buffer.from(
samlToken.replace("\r\n", ""),
"utf8",
);
const gZipToken = await gzip(bufferSamlToken);
localDevToken = gZipToken
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/g, "");
And I want to do the same in the frontend. How can I achieve it ?
This is what I've tried using the Pako library from https://github.com/nodeca/pako
function convertSamlToken(input) {
var samlToken = input.replace("\r\n", "");
samlToken = pako.gzip(samlToken, {
to: 'string'
});
samlToken = btoa(samlToken)
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/g, "");
return samlToken;
}
But the output is different. What is wrong ?