Add a route to kill tunnel if open with same JWT token

This commit is contained in:
Olivier MICHAUD
2021-05-19 22:28:42 +02:00
parent 1371d03fec
commit 1204fdf99a
5 changed files with 117 additions and 12 deletions
+18 -1
View File
@@ -2,6 +2,7 @@ import http from 'http';
import Debug from 'debug';
import pump from 'pump';
import EventEmitter from 'events';
import jwt from 'jsonwebtoken';
// A client encapsulates req/res handling using an agent
//
@@ -13,6 +14,7 @@ class Client extends EventEmitter {
const agent = this.agent = options.agent;
const id = this.id = options.id;
this.securityToken = options.securityToken;
this.debug = Debug(`lt:Client[${this.id}]`);
@@ -45,6 +47,21 @@ class Client extends EventEmitter {
});
}
isSecurityTokenEqual(securityToken) {
const decodeJWT = (token) => {
return jwt.decode(token.replace(/Bearer /, ''), {complete: false});
}
if (this.securityToken === null) {
return false;
}
try{
return decodeJWT(this.securityToken).name === decodeJWT(securityToken).name;
}catch(error){
this.debug('error with jwt %s %s', securityToken, error);
return false;
}
}
stats() {
return this.agent.stats();
}
@@ -129,4 +146,4 @@ class Client extends EventEmitter {
}
}
export default Client;
export default Client;