removed most async funtions

This commit is contained in:
2024-01-23 15:48:05 +01:00
parent 23b873767f
commit ae41f81aaa
6 changed files with 62 additions and 28 deletions
+41 -2
View File
@@ -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
+2 -2
View File
@@ -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
+10 -10
View File
@@ -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;
}
+7 -12
View File
@@ -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",
+1 -1
View File
@@ -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": {
+1 -1
View File
@@ -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;