From 060c844468f1afcd7fdc9b525659e30b26dd078b Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Wed, 24 Nov 2021 19:24:43 +0100 Subject: [PATCH] Fix htag in localstorage Signed-off-by: Gregoire Parant --- front/src/Connexion/ConnectionManager.ts | 16 +++++++++++---- front/src/Connexion/Room.ts | 4 ++++ front/src/Phaser/Game/GameManager.ts | 1 + front/src/Url/UrlManager.ts | 3 ++- .../src/Controller/AuthenticateController.ts | 20 ++++++++++++++++--- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index a8b172e6..22289895 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -176,8 +176,9 @@ class ConnectionManager { //before set token of user we must load room and all information. For example the mandatory authentication could be require on current room this._currentRoom = await Room.createRoom(new URL(roomPath)); - //defined last room url this room path - localUserStore.setLastRoomUrl(this._currentRoom.key); + //Set last room visited! (connected or nor, must to be saved in localstorage and cache API) + //use href to keep # value + localUserStore.setLastRoomUrl(this._currentRoom.href); //todo: add here some kind of warning if authToken has expired. if (!this.authToken && !this._currentRoom.authenticationMandatory) { @@ -188,8 +189,15 @@ class ConnectionManager { analyticsClient.loggedWithSso(); } catch (err) { console.error(err); - this.loadOpenIDScreen(); - return Promise.reject(new Error("You will be redirect on login page")); + //if user must to be connect in current room or pusher error is not openid provier access error + //try to connected with function loadOpenIDScreen + if ( + this._currentRoom.authenticationMandatory || + (err.response?.data && err.response.data !== "User cannot to be connected on openid provier") + ) { + this.loadOpenIDScreen(); + return Promise.reject(new Error("You will be redirect on login page")); + } } } this.localUser = localUserStore.getLocalUser() as LocalUser; //if authToken exist in localStorage then localUser cannot be null diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index f206d318..4c5955cc 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -176,6 +176,10 @@ export class Room { return newUrl.toString(); } + public get href(): string { + return this.roomUrl.toString(); + } + get textures(): CharacterTexture[] | undefined { return this._textures; } diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 1bf18d8d..04db08a3 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -45,6 +45,7 @@ export class GameManager { return EnableCameraSceneName; } else { this.activeMenuSceneAndHelpCameraSettings(); + //TODO fix to return href with # saved in localstorage return this.startRoom.key; } } diff --git a/front/src/Url/UrlManager.ts b/front/src/Url/UrlManager.ts index f1e15db1..50dbedc9 100644 --- a/front/src/Url/UrlManager.ts +++ b/front/src/Url/UrlManager.ts @@ -40,7 +40,8 @@ class UrlManager { public pushRoomIdToUrl(room: Room): void { if (window.location.pathname === room.id) return; //Set last room visited! (connected or nor, must to be saved in localstorage and cache API) - localUserStore.setLastRoomUrl(room.key); + //use href to keep # value + localUserStore.setLastRoomUrl(room.href); const hash = window.location.hash; const search = room.search.toString(); history.pushState({}, "WorkAdventure", room.id + (search ? "?" + search : "") + hash); diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index fb428141..47d35fab 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -5,7 +5,7 @@ import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi"; import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager"; import { parse } from "query-string"; import { openIDClient } from "../Services/OpenIDClient"; -import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable"; +import { DISABLE_ANONYMOUS, FRONT_URL } from "../Enum/EnvironmentVariable"; export interface TokenInterface { userUuid: string; @@ -80,7 +80,11 @@ export class AuthenticateController extends BaseController { this.addCorsHeaders(res); return res.end(JSON.stringify({ ...resUserData, authToken: token })); } - throw Error("Token cannot to be check on Hydra"); + console.error("Token cannot to be check on OpenId provider"); + res.writeStatus("500"); + res.writeHeader("Access-Control-Allow-Origin", FRONT_URL); + res.end("User cannot to be connected on openid provier"); + return; } const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken); @@ -93,7 +97,17 @@ export class AuthenticateController extends BaseController { } //user have not token created, check data on hydra and create token - const userInfo = await openIDClient.getUserInfo(code as string, nonce as string); + let userInfo = null; + try { + userInfo = await openIDClient.getUserInfo(code as string, nonce as string); + } catch (err) { + //if no access on openid provider, return error + console.error("User cannot to be connected on OpenId provider => ", err); + res.writeStatus("500"); + res.writeHeader("Access-Control-Allow-Origin", FRONT_URL); + res.end("User cannot to be connected on openid provier"); + return; + } const email = userInfo.email || userInfo.sub; if (!email) { throw new Error("No email in the response");