diff --git a/README.md b/README.md index 8a652c9..a471f29 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This library is easy to integrate into your project and offers a comprehensive s To install Guardian, simply run the following command using npm: ```bash -npm install Guardian +npm install auth-guardian ``` ## Features @@ -40,6 +40,44 @@ Guardian's `PasswordGenerator` class allows you to generate strong, random passw ## Usage/Examples +### for imports + +#### import only jwtAuth + +```javascript +const { JwtAuth } = require('guardian'); +``` + +#### import only passPolicy + +```javascript +const { PassPolicy } = require('guardian'); +``` + +#### import only passCheck + +```javascript +const { PassCheck } = require('guardian'); +``` + +#### import only rateLimiter + +```javascript +const { RateLimiter } = require('guardian'); +``` + +#### import only passwordGenerator + +```javascript +const { PasswordGenerator } = require('guardian'); +``` + +#### import all + +```javascript +const { JwtAuth, PassPolicy, PassCheck, RateLimiter, PasswordGenerator } = require('guardian'); +``` + ### JSON Web Token (JWT) Management - JwtAuth #### Initialize JwtAuth @@ -257,7 +295,8 @@ const randomPassword = passwordGenerator.Generate(); ## Authors -- [kajvan](https://www.github.com/kajvan) +- [kajvan](https://www.github.com/kajvans) +- [kajvan](https://gitea.quiztimes.nl/kajvans) ## License diff --git a/index.js b/index.js index 5de6755..ede726f 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,12 @@ const PassCheck = require('./passwordcheck'); -const JWTManager = require('./jwt'); +const JWTAuth = require('./jwt'); const RateLimiter = require('./ratelimit'); const PassPolicy = require('./passpolicy'); const PasswordGenerator = require('./passgen'); module.exports = { PassCheck, - JWTManager, + JWTAuth, RateLimiter, PassPolicy, PasswordGenerator diff --git a/jwt.js b/jwt.js index 0f73f95..f7c6047 100644 --- a/jwt.js +++ b/jwt.js @@ -6,36 +6,36 @@ class JwtAuth{ this.blacklist = []; } - async generateJWT(payload, settings, secretKey = this.JWTSecretKey) { + generateJWT(payload, settings, secretKey = this.JWTSecretKey) { return jwt.sign(payload, secretKey, settings); } - async verifyJWT(token, secretKey = this.JWTSecretKey) { + verifyJWT(token, secretKey = this.JWTSecretKey) { if(this.blacklist.includes(token)) return { valid: false, message: "Token is blacklisted." }; return jwt.verify(token, secretKey); } - async decodeJWT(token) { + decodeJWT(token) { if(this.blacklist.includes(token)) return { valid: false, message: "Token is blacklisted." }; return jwt.decode(token); } - async getJWTExpirationDate(token) { + getJWTExpirationDate(token) { if(this.blacklist.includes(token)) return { valid: false, message: "Token is blacklisted." }; - const decoded = await this.decodeJWT(token); + const decoded = this.decodeJWT(token); return decoded.exp; } - async isJWTExpired(token) { + isJWTExpired(token) { if(this.blacklist.includes(token)) return { valid: false, message: "Token is blacklisted." }; - const expirationDate = await this.getJWTExpirationDate(token); + const expirationDate = this.getJWTExpirationDate(token); return expirationDate < Date.now(); } - async refreshJWT(token, settings, secretKey = this.JWTSecretKey) { + refreshJWT(token, settings, secretKey = this.JWTSecretKey) { if(this.blacklist.includes(token)) return { valid: false, message: "Token is blacklisted." }; - const decoded = await this.verifyJWT(token, secretKey); - const newToken = await this.generateJWT(decoded, settings, secretKey); + const decoded = this.verifyJWT(token, secretKey); + const newToken = this.generateJWT(decoded, settings, secretKey); return newToken; } diff --git a/package-lock.json b/package-lock.json index cec8e1e..fe9a221 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "guardian", - "version": "0.0.1", + "name": "auth-guardian", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "guardian", - "version": "0.0.1", + "name": "auth-guardian", + "version": "1.0.2", "license": "MIT", "dependencies": { "bcrypt": "^5.1.1", @@ -147,11 +147,6 @@ } } }, - "node_modules/debug/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, "node_modules/delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", @@ -444,9 +439,9 @@ } }, "node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/node-addon-api": { "version": "5.1.0", diff --git a/package.json b/package.json index d8ba433..c7d4412 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth-guardian", - "version": "1.0.1", + "version": "1.0.2", "description": "auth-guardian a library for enhancing application security", "main": "index.js", "scripts": { diff --git a/passgen.js b/passgen.js index 3e16b3d..be09b6d 100644 --- a/passgen.js +++ b/passgen.js @@ -12,7 +12,7 @@ class PasswordGenerator{ this.options = { ...defaultOptions, ...options }; } - Generate(){ + async Generate(){ // Generate random password that complies with the options const { minLength, maxLength, minLower, minUpper, minNum, minSpecial, specialChars } = this.options;