Hello Netta,
We are just sharing a sample node JS code to generate tokens from the parent application to implement custom token based SSO method. This is for your reference, you can make the changes in this code as per your requirement and enhance it.
const crypto = require('crypto');
function encrypt(strToEncrypt) {
try {
const key = 'HSpnzzfCLqrBn8Lk';
const algorithm = 'aes-128-ecb';
const cipher = crypto.createCipheriv(algorithm, Buffer.from(key, 'utf-8'), null);
cipher.setAutoPadding(true);
let encrypted = cipher.update(strToEncrypt, 'utf-8', 'base64');
encrypted += cipher.final('base64');
encrypted = encrypted.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
return encrypted;
} catch (error) {
console.error("Encryption error:", error);
return null;
}
}
const encryptedText = encrypt("Company=Helical|username=ssouser|role=admin");
console.log("Encrypted:", encryptedText);
Thank You,
Helical Insight Team.