Commit 229e2a8e by Percy Quispe Huarcaya

feat: Adding token creator and a parser

parent 98b26cf6
{
"name": "security-ndjs-lib",
"version": "1.0.0",
"description": "",
"description": "Library to manage tokens using js",
"main": "index.js",
"scripts": {
"test": "jest"
......
......@@ -4,7 +4,7 @@ const { getDefaultPath } = require('./util/osutils')
require('dotenv').config({path: getDefaultPath('global') + "/.env"});
const apiKey = process.env.API_KEY;
const tokenAlgorithm = process.env.TOKEN_ALGORITHM
createJWT = (id, subject, ...time) => {
return createToken(id, "oliverpqh@gmail.com", subject, time);
}
......@@ -24,7 +24,7 @@ createToken = (id, issuer, subject, ...time) => {
// Set expiration if provided
const options = {
algorithm: 'HS512'
algorithm: tokenAlgorithm
};
if (ttlMillis >= 0) {
......@@ -42,7 +42,7 @@ parseJWT = (token, ...id) => {
try {
// Verify and decode the token using token and private key
const decoded = jwt.verify(token, Buffer.from(apiKey, 'base64'), {
algorithms: ['HS512'] // Ensure it matches the algorithm used when creating the token
algorithms: [tokenAlgorithm] // Ensure it matches the algorithm used when creating the token
});
/* // if one day we want to validate the id
if(id[0]){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment