Add client token authentication
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user