Add client token authentication

This commit is contained in:
Maxim Rubis
2018-06-06 08:05:34 -04:00
parent d9fca62c17
commit 6a103f3e61
3 changed files with 25 additions and 11 deletions
+8 -5
View File
@@ -26,15 +26,18 @@ class ClientManager {
}
// create a new tunnel with `id`
// if the id is already used, a random id is assigned
// if the tunnel could not be created, throws an error
async newClient(id) {
async newClient (id, token) {
const clients = this.clients;
const stats = this.stats;
// can't ask for id already is use
if (clients[id]) {
if (clients[id] !== undefined) {
if(this.opt.tokens[id] !== undefined) {
return Promise.reject(new Error('Client is already connected. Try again later.'));
}
id = hri.random();
} else if(this.opt.tokens[id] !== undefined && this.opt.tokens[id] !== token) {
return Promise.reject(new Error('Token is not found or correct.'));
}
const maxSockets = this.opt.max_tcp_sockets;