SSO code for NodeJS application

Hello Team,

I am using helical insight 5.2.1. I am trying to implement SSO (external token-based authentication ) and the blog I am following is

I see that there is already sample java code as well as description of the algorithm to be followed mentioned in the blog. My application is in Node JS. Would you have sample code for Node JS also?

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.