I managed to do, these two codes worked for me
TESTE4
const uuidv4 = require('uuid/v4');
let code = uuidv4()
console.log("Code: " + code);
let hexadecimal = CryptoJS.enc.Hex.parse(code)
console.log("Hexadecimal: " + hexadecimal);
let base64 = CryptoJS.enc.Base64.stringify(hexadecimal).replace(/[\/]/g, '_').replace(/[+]g, '-').replace(/[=]/g, '')
console.log("HexToBase64: " + base64);
let sha256 = CryptoJS.SHA256(base64)
console.log("Base64ToSHA256: " + sha256);
let sha256_base64 = CryptoJS.enc.Base64.stringify(sha256).replace(/[\/]/g, '_').replace(/[+]/g, '-').replace(/[=]/g, '')
console.log("Sha256toBase64: " + sha256_base64);
TESTE5
const randomize = require('randomatic');
let code1 = randomize(32)
console.log('Code: ' + code1);
let hexadecimal1 = CryptoJS.enc.Hex.parse(code1)
console.log('CodeToHex: ' + hexadecimal1);
let base641 = CryptoJS.enc.Base64.stringify(hexadecimal1).replace(/[\/]/g, '_').replace(/[+]/g, '-').replace(/[=]/g, '')
console.log('HexToBase64: ' + base641);
let sha2561 = CryptoJS.SHA256(base641)
console.log('Base64ToSHA256: ' + sha2561);
let sha256_base641 = CryptoJS.enc.Base64.stringify(sha2561).replace(/[\/]/g, '_').replace(/[+]/g, '-').replace(/[=]/g, '')
console.log('Sha256ToBase64: ' + sha256_base641);
You need to study both languages to understand the differences. anyway, a lot of php has not ready in javascript, will need to look for various solutions to convert this code
– Ricardo Pontual
have you searched the site? should have answers to all this, check it out: https://answall.com/q/295491/57220
– Ricardo Pontual
generate a token must be made from the "server side", so you need to do this in php, otherwise your code will not be safe, can be easily manipulated
– Ricardo Pontual