From 928e486de569d4f603df172b5e199ab0594216eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 10 Jun 2020 12:32:39 +0200 Subject: [PATCH] Fixing token management --- back/src/Controller/IoSocketController.ts | 5 ++++- back/src/Model/Websocket/ExSocketInterface.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index 78efe558..edda6de9 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -60,13 +60,16 @@ export class IoSocketController { // Completely commented for now, as we do not use the "/login" route at all. this.Io.use((socket: Socket, next) => { if (!socket.handshake.query || !socket.handshake.query.token) { + console.error('An authentication error happened, a user tried to connect without a token.'); return next(new Error('Authentication error')); } if(this.searchClientByToken(socket.handshake.query.token)){ + console.error('An authentication error happened, a user tried to connect while its token is already connected.'); return next(new Error('Authentication error')); } Jwt.verify(socket.handshake.query.token, SECRET_KEY, (err: JsonWebTokenError, tokenDecoded: object) => { if (err) { + console.error('An authentication error happened, invalid JsonWebToken.', err); return next(new Error('Authentication error')); } @@ -74,7 +77,7 @@ export class IoSocketController { return next(new Error('Authentication error, invalid token structure')); } - (socket as ExSocketInterface).token = tokenDecoded; + (socket as ExSocketInterface).token = socket.handshake.query.token; (socket as ExSocketInterface).userId = tokenDecoded.userId; next(); }); diff --git a/back/src/Model/Websocket/ExSocketInterface.ts b/back/src/Model/Websocket/ExSocketInterface.ts index e821e296..5827ccc9 100644 --- a/back/src/Model/Websocket/ExSocketInterface.ts +++ b/back/src/Model/Websocket/ExSocketInterface.ts @@ -4,7 +4,7 @@ import {Identificable} from "./Identificable"; import {TokenInterface} from "../../Controller/AuthenticateController"; export interface ExSocketInterface extends Socket, Identificable { - token: TokenInterface; + token: string; roomId: string; webRtcRoomId: string; userId: string;