From c1dc438138f5ec474f9407944c00428d45955178 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 11:14:27 +0100 Subject: [PATCH 1/9] HotFix encrypted and decrypted error Signed-off-by: Gregoire Parant --- front/src/Connexion/Room.ts | 48 ++++++++++++++++---------- pusher/src/Controller/MapController.ts | 15 +++++--- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 535d2f8d..0f4bb20c 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -89,27 +89,37 @@ export class Room { } private async getMapDetail(): Promise { - const result = await Axios.get(`${PUSHER_URL}/map`, { - params: { - playUri: this.roomUrl.toString(), - authToken: localUserStore.getAuthToken(), - }, - }); + try { + const result = await Axios.get(`${PUSHER_URL}/map`, { + params: { + playUri: this.roomUrl.toString(), + authToken: localUserStore.getAuthToken(), + }, + }); - const data = result.data; - if (data.redirectUrl) { - return { - redirectUrl: data.redirectUrl as string, - }; + const data = result.data; + if (data.redirectUrl) { + return { + redirectUrl: data.redirectUrl as string, + }; + } + console.log("Map ", this.id, " resolves to URL ", data.mapUrl); + this._mapUrl = data.mapUrl; + this._textures = data.textures; + this._group = data.group; + this._authenticationMandatory = data.authenticationMandatory || (DISABLE_ANONYMOUS as boolean); + this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER; + this._contactPage = data.contactPage || CONTACT_URL; + return new MapDetail(data.mapUrl, data.textures); + } catch (e) { + console.log("Error => getMapDetail", e, e.response); + //TODO fix me and manage Error class + if (e.response?.data === "Token decrypted error") { + localUserStore.setAuthToken(null); + window.location.assign("/login"); + } + throw e; } - console.log("Map ", this.id, " resolves to URL ", data.mapUrl); - this._mapUrl = data.mapUrl; - this._textures = data.textures; - this._group = data.group; - this._authenticationMandatory = data.authenticationMandatory || (DISABLE_ANONYMOUS as boolean); - this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER; - this._contactPage = data.contactPage || CONTACT_URL; - return new MapDetail(data.mapUrl, data.textures); } /** diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 18748d9e..d7d506e2 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -80,10 +80,17 @@ export class MapController extends BaseController { authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string); userId = authTokenData.identifier; } catch (e) { - // Decode token, in this case we don't need to create new token. - authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true); - userId = authTokenData.identifier; - console.info("JWT expire, but decoded", userId); + try { + // Decode token, in this case we don't need to create new token. + authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true); + userId = authTokenData.identifier; + console.info("JWT expire, but decoded", userId); + } catch (e) { + // The token was not good, redirect user on login page + res.writeStatus("500"); + res.end("Token decrypted error"); + return; + } } } const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId); From ec1cc92c8b12b36d8d08483e58b758593ba8c015 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 11:23:18 +0100 Subject: [PATCH 2/9] replace console log by error Signed-off-by: Gregoire Parant --- front/src/Connexion/Room.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 0f4bb20c..dd80b704 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -112,7 +112,7 @@ export class Room { this._contactPage = data.contactPage || CONTACT_URL; return new MapDetail(data.mapUrl, data.textures); } catch (e) { - console.log("Error => getMapDetail", e, e.response); + console.error("Error => getMapDetail", e, e.response); //TODO fix me and manage Error class if (e.response?.data === "Token decrypted error") { localUserStore.setAuthToken(null); From 87683744602f770b36756e4c297123514b1c65e6 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 13:14:40 +0100 Subject: [PATCH 3/9] HotFix connexion manager Signed-off-by: Gregoire Parant --- front/src/Connexion/ConnectionManager.ts | 2 +- front/src/Enum/EnvironmentVariable.ts | 2 +- front/src/Phaser/Game/GameScene.ts | 4 +++- pusher/src/Controller/AuthenticateController.ts | 14 +++++++++++++- pusher/src/Enum/EnvironmentVariable.ts | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 00e721ae..fbff365c 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -314,7 +314,7 @@ class ConnectionManager { } } const { authToken, userUuid, textures, email } = await Axios.get(`${PUSHER_URL}/login-callback`, { - params: { code, nonce, token }, + params: { code, nonce, token, playUri: this.currentRoom?.key }, }).then((res) => res.data); localUserStore.setAuthToken(authToken); this.localUser = new LocalUser(userUuid, textures, email); diff --git a/front/src/Enum/EnvironmentVariable.ts b/front/src/Enum/EnvironmentVariable.ts index 644b7a77..76b4c8af 100644 --- a/front/src/Enum/EnvironmentVariable.ts +++ b/front/src/Enum/EnvironmentVariable.ts @@ -23,7 +23,7 @@ export const CONTACT_URL = process.env.CONTACT_URL || undefined; export const PROFILE_URL = process.env.PROFILE_URL || undefined; export const POSTHOG_API_KEY: string = (process.env.POSTHOG_API_KEY as string) || ""; export const POSTHOG_URL = process.env.POSTHOG_URL || undefined; -export const DISABLE_ANONYMOUS = process.env.DISABLE_ANONYMOUS || false; +export const DISABLE_ANONYMOUS: boolean = process.env.DISABLE_ANONYMOUS === "true"; export const OPID_LOGIN_SCREEN_PROVIDER = process.env.OPID_LOGIN_SCREEN_PROVIDER; export const isMobile = (): boolean => window.innerWidth <= 800 || window.innerHeight <= 600; diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 4812c142..81cf3676 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -88,6 +88,7 @@ import { analyticsClient } from "../../Administration/AnalyticsClient"; import { get } from "svelte/store"; import { contactPageStore } from "../../Stores/MenuStore"; import { GameMapProperties } from "./GameMapProperties"; +import SpriteSheetFile = Phaser.Loader.FileTypes.SpriteSheetFile; export interface GameSceneInitInterface { initPosition: PointInterface | null; @@ -293,7 +294,8 @@ export class GameScene extends DirtyScene { } //once preloading is over, we don't want loading errors to crash the game, so we need to disable this behavior after preloading. - if (this.preloading) { + //if SpriteSheetFile (WOKA file) don't display error and give an access for user + if (this.preloading && !(file instanceof SpriteSheetFile)) { //remove loader in progress removeLoader(this); diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index f505923c..5e4eb19f 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -64,6 +64,18 @@ export class AuthenticateController extends BaseController { try { const authTokenData: AuthTokenData = jwtTokenManager.verifyJWTToken(token as string, false); if (authTokenData.accessToken == undefined) { + //if not nonce and code, user connected in anonymous + //get data with identifier and return token + if (!code && !nonce) { + const data = await this.getUserByUserIdentifier( + authTokenData.identifier, + playUri as string, + IPAddress + ); + res.writeStatus("200"); + this.addCorsHeaders(res); + return res.end(JSON.stringify({ ...data, authToken: token })); + } throw Error("Token cannot to be check on Hydra"); } const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken); @@ -81,7 +93,7 @@ export class AuthenticateController extends BaseController { if (!email) { throw new Error("No email in the response"); } - const authToken = jwtTokenManager.createAuthToken(email, userInfo.access_token); + const authToken = jwtTokenManager.createAuthToken(email, userInfo?.access_token); //Get user data from Admin Back Office //This is very important to create User Local in LocalStorage in WorkAdventure diff --git a/pusher/src/Enum/EnvironmentVariable.ts b/pusher/src/Enum/EnvironmentVariable.ts index 3b55579f..127af38f 100644 --- a/pusher/src/Enum/EnvironmentVariable.ts +++ b/pusher/src/Enum/EnvironmentVariable.ts @@ -18,7 +18,7 @@ export const OPID_CLIENT_SECRET = process.env.OPID_CLIENT_SECRET || ""; export const OPID_CLIENT_ISSUER = process.env.OPID_CLIENT_ISSUER || ""; export const OPID_CLIENT_REDIRECT_URL = process.env.OPID_CLIENT_REDIRECT_URL || FRONT_URL + "/jwt"; export const OPID_PROFILE_SCREEN_PROVIDER = process.env.OPID_PROFILE_SCREEN_PROVIDER || ADMIN_URL + "/profile"; -export const DISABLE_ANONYMOUS = process.env.DISABLE_ANONYMOUS || false; +export const DISABLE_ANONYMOUS: boolean = process.env.DISABLE_ANONYMOUS === "true"; export { SECRET_KEY, From ba89d9b1221796025a85468eafaab1b478a9e322 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 13:18:40 +0100 Subject: [PATCH 4/9] HotFix DISABLED_ROOM for env variable Signed-off-by: Gregoire Parant --- front/src/Connexion/Room.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index dd80b704..2f408126 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -14,7 +14,7 @@ export interface RoomRedirect { export class Room { public readonly id: string; public readonly isPublic: boolean; - private _authenticationMandatory: boolean = DISABLE_ANONYMOUS as boolean; + private _authenticationMandatory: boolean = DISABLE_ANONYMOUS; private _iframeAuthentication?: string = OPID_LOGIN_SCREEN_PROVIDER; private _mapUrl: string | undefined; private _textures: CharacterTexture[] | undefined; @@ -107,7 +107,7 @@ export class Room { this._mapUrl = data.mapUrl; this._textures = data.textures; this._group = data.group; - this._authenticationMandatory = data.authenticationMandatory || (DISABLE_ANONYMOUS as boolean); + this._authenticationMandatory = data.authenticationMandatory || DISABLE_ANONYMOUS; this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER; this._contactPage = data.contactPage || CONTACT_URL; return new MapDetail(data.mapUrl, data.textures); From e54732be1bf7560693915c4e9006a03f84dc072f Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 14:46:32 +0100 Subject: [PATCH 5/9] HotFix authentication manager to get data from back Signed-off-by: Gregoire Parant --- front/src/Connexion/ConnectionManager.ts | 2 +- .../src/Controller/AuthenticateController.ts | 28 +++++++++++++------ pusher/src/Controller/IoSocketController.ts | 1 + pusher/src/Services/AdminApi.ts | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index fbff365c..ffd91d39 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -226,7 +226,7 @@ class ConnectionManager { public async anonymousLogin(isBenchmark: boolean = false): Promise { const data = await Axios.post(`${PUSHER_URL}/anonymLogin`).then((res) => res.data); - this.localUser = new LocalUser(data.userUuid, []); + this.localUser = new LocalUser(data.userUuid, [], data.email); this.authToken = data.authToken; if (!isBenchmark) { // In benchmark, we don't have a local storage. diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index 5e4eb19f..fb428141 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -63,25 +63,30 @@ export class AuthenticateController extends BaseController { if (token != undefined) { try { const authTokenData: AuthTokenData = jwtTokenManager.verifyJWTToken(token as string, false); + + //Get user data from Admin Back Office + //This is very important to create User Local in LocalStorage in WorkAdventure + const resUserData = await this.getUserByUserIdentifier( + authTokenData.identifier, + playUri as string, + IPAddress + ); + if (authTokenData.accessToken == undefined) { //if not nonce and code, user connected in anonymous //get data with identifier and return token if (!code && !nonce) { - const data = await this.getUserByUserIdentifier( - authTokenData.identifier, - playUri as string, - IPAddress - ); res.writeStatus("200"); this.addCorsHeaders(res); - return res.end(JSON.stringify({ ...data, authToken: token })); + return res.end(JSON.stringify({ ...resUserData, authToken: token })); } throw Error("Token cannot to be check on Hydra"); } + const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken); res.writeStatus("200"); this.addCorsHeaders(res); - return res.end(JSON.stringify({ ...resCheckTokenAuth, authToken: token })); + return res.end(JSON.stringify({ ...resCheckTokenAuth, ...resUserData, authToken: token })); } catch (err) { console.info("User was not connected", err); } @@ -261,7 +266,14 @@ export class AuthenticateController extends BaseController { playUri: string, IPAddress: string ): Promise { - let data: FetchMemberDataByUuidResponse | object = {}; + let data: FetchMemberDataByUuidResponse = { + email: email, + userUuid: email, + tags: [], + messages: [], + visitCardUrl: null, + textures: [], + }; try { data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress); } catch (err) { diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index 9b6c1510..35fd08d5 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -189,6 +189,7 @@ export class IoSocketController { let memberTextures: CharacterTexture[] = []; const room = await socketManager.getOrCreateRoom(roomId); let userData: FetchMemberDataByUuidResponse = { + email: userIdentifier, userUuid: userIdentifier, tags: [], visitCardUrl: null, diff --git a/pusher/src/Services/AdminApi.ts b/pusher/src/Services/AdminApi.ts index 6e1848eb..416b9cb6 100644 --- a/pusher/src/Services/AdminApi.ts +++ b/pusher/src/Services/AdminApi.ts @@ -22,6 +22,7 @@ export interface AdminBannedData { } export interface FetchMemberDataByUuidResponse { + email: string; userUuid: string; tags: string[]; visitCardUrl: string | null; From 0614fa7b47251d3a0bd9347a0f8f0974efc1b32c Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 15:03:54 +0100 Subject: [PATCH 6/9] HotFix copy link to share it Signed-off-by: Gregoire Parant --- front/src/Components/Menu/AboutRoomSubMenu.svelte | 8 +++++--- front/src/Components/Menu/GuestSubMenu.svelte | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/front/src/Components/Menu/AboutRoomSubMenu.svelte b/front/src/Components/Menu/AboutRoomSubMenu.svelte index 16b5c057..2a546a14 100644 --- a/front/src/Components/Menu/AboutRoomSubMenu.svelte +++ b/front/src/Components/Menu/AboutRoomSubMenu.svelte @@ -40,7 +40,9 @@ }) function copyLink() { - HTMLShareLink.select(); + const input: HTMLInputElement = document.getElementById('input-share-link') as HTMLInputElement; + input.focus(); + input.select(); document.execCommand('copy'); } @@ -59,12 +61,12 @@

Share the link of the room !

- +

Information on the map

diff --git a/front/src/Components/Menu/GuestSubMenu.svelte b/front/src/Components/Menu/GuestSubMenu.svelte index 13a7981a..d054ff4d 100644 --- a/front/src/Components/Menu/GuestSubMenu.svelte +++ b/front/src/Components/Menu/GuestSubMenu.svelte @@ -2,7 +2,9 @@ let HTMLShareLink: HTMLInputElement; function copyLink() { - HTMLShareLink.select(); + const input: HTMLInputElement = document.getElementById('input-share-link') as HTMLInputElement; + input.focus(); + input.select(); document.execCommand('copy'); } @@ -22,12 +24,12 @@

Share the link of the room !

- +
From e5979998c5348cc7e124607eb11690e2b2bec635 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 16 Nov 2021 15:28:54 +0100 Subject: [PATCH 7/9] Update design of credit page Signed-off-by: Gregoire Parant --- .../Components/Menu/AboutRoomSubMenu.svelte | 59 +------------------ front/src/Components/Menu/GuestSubMenu.svelte | 6 +- 2 files changed, 3 insertions(+), 62 deletions(-) diff --git a/front/src/Components/Menu/AboutRoomSubMenu.svelte b/front/src/Components/Menu/AboutRoomSubMenu.svelte index 2a546a14..6c10cc76 100644 --- a/front/src/Components/Menu/AboutRoomSubMenu.svelte +++ b/front/src/Components/Menu/AboutRoomSubMenu.svelte @@ -4,7 +4,6 @@ let gameScene = gameManager.getCurrentGameScene(); - let HTMLShareLink: HTMLInputElement; let expandedMapCopyright = false; let expandedTilesetCopyright = false; @@ -38,37 +37,9 @@ } } }) - - function copyLink() { - const input: HTMLInputElement = document.getElementById('input-share-link') as HTMLInputElement; - input.focus(); - input.select(); - document.execCommand('copy'); - } - - async function shareLink() { - const shareData = {url: location.toString()}; - - try { - await navigator.share(shareData); - } catch (err) { - console.error('Error: ' + err); - copyLink(); - } - }
- -
-

Share the link of the room !

- - -

Information on the map

{mapName}

@@ -95,24 +66,6 @@ div.about-room-main { height: calc(100% - 56px); - section.share-url { - text-align: center; - margin-bottom: 20px; - - input { - width: 85%; - border-radius: 32px; - padding: 3px; - } - input::selection { - background-color: #209cee; - } - } - - section.is-mobile { - display: none; - } - h2, h3 { width: 100%; text-align: center; @@ -128,21 +81,11 @@ margin: 0; padding: 0; overflow-y: auto; - } + } } @media only screen and (max-width: 800px), only screen and (max-height: 800px) { div.about-room-main { - section.share-url.not-mobile { - display: none; - } - - section.is-mobile { - display: block; - text-align: center; - margin-bottom: 20px; - } - section.container-overflow { height: calc(100% - 120px); } diff --git a/front/src/Components/Menu/GuestSubMenu.svelte b/front/src/Components/Menu/GuestSubMenu.svelte index d054ff4d..bda16ca5 100644 --- a/front/src/Components/Menu/GuestSubMenu.svelte +++ b/front/src/Components/Menu/GuestSubMenu.svelte @@ -1,6 +1,4 @@