From 6cf86ec8dc023641438e38119a29cd5c6e313d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gr=C3=A9goire=20parant?= Date: Wed, 8 Sep 2021 13:39:46 +0200 Subject: [PATCH] Add play uri for login and register in hydra (#1421) Signed-off-by: Gregoire Parant --- front/dist/.htaccess | 2 ++ front/src/Connexion/ConnectionManager.ts | 10 +++++----- pusher/src/Controller/AuthenticateController.ts | 8 ++++++-- pusher/src/Services/OpenIDClient.ts | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/front/dist/.htaccess b/front/dist/.htaccess index 72c4d724..522fc2af 100644 --- a/front/dist/.htaccess +++ b/front/dist/.htaccess @@ -22,3 +22,5 @@ RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule "^[_@]/" "/index.html" [L] RewriteRule "^register/" "/index.html" [L] +RewriteRule "^login" "/index.html" [L] +RewriteRule "^jwt/" "/index.html" [L] diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 2010689c..0dc3493f 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -45,7 +45,7 @@ class ConnectionManager { loginSceneVisibleIframeStore.set(false); return null; } - const redirectUrl = `${this._currentRoom.iframeAuthentication}?state=${state}&nonce=${nonce}`; + const redirectUrl = `${this._currentRoom.iframeAuthentication}?state=${state}&nonce=${nonce}&playUri=${this._currentRoom.key}`; window.location.assign(redirectUrl); return redirectUrl; } @@ -76,10 +76,9 @@ class ConnectionManager { this.connexionType = connexionType; this._currentRoom = null; if (connexionType === GameConnexionTypes.login) { - //TODO clear all cash and redirect on login scene (iframe) - localUserStore.setAuthToken(null); this._currentRoom = await Room.createRoom(new URL(localUserStore.getLastRoomUrl())); - urlManager.pushRoomIdToUrl(this._currentRoom); + this.loadOpenIDScreen(); + return Promise.reject(new Error("You will be redirect on login page")); } else if (connexionType === GameConnexionTypes.jwt) { const urlParams = new URLSearchParams(window.location.search); const code = urlParams.get("code"); @@ -91,13 +90,14 @@ class ConnectionManager { throw "No Auth code provided"; } localUserStore.setCode(code); + this._currentRoom = await Room.createRoom(new URL(localUserStore.getLastRoomUrl())); try { await this.checkAuthUserConnexion(); } catch (err) { console.error(err); this.loadOpenIDScreen(); + return Promise.reject(new Error("You will be redirect on login page")); } - this._currentRoom = await Room.createRoom(new URL(localUserStore.getLastRoomUrl())); urlManager.pushRoomIdToUrl(this._currentRoom); } else if (connexionType === GameConnexionTypes.register) { //@deprecated diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index 000ac0ca..6403a8f1 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -27,13 +27,17 @@ export class AuthenticateController extends BaseController { console.warn("/message request was aborted"); }); - const { nonce, state } = parse(req.getQuery()); + const { nonce, state, playUri } = parse(req.getQuery()); if (!state || !nonce) { res.writeStatus("400 Unauthorized").end("missing state and nonce URL parameters"); return; } try { - const loginUri = await openIDClient.authorizationUrl(state as string, nonce as string); + const loginUri = await openIDClient.authorizationUrl( + state as string, + nonce as string, + playUri as string | undefined + ); res.writeStatus("302"); res.writeHeader("Location", loginUri); return res.end(); diff --git a/pusher/src/Services/OpenIDClient.ts b/pusher/src/Services/OpenIDClient.ts index b6506a5e..da636c02 100644 --- a/pusher/src/Services/OpenIDClient.ts +++ b/pusher/src/Services/OpenIDClient.ts @@ -20,13 +20,14 @@ class OpenIDClient { return this.issuerPromise; } - public authorizationUrl(state: string, nonce: string) { + public authorizationUrl(state: string, nonce: string, playUri?: string) { return this.initClient().then((client) => { return client.authorizationUrl({ scope: "openid email", prompt: "login", state: state, nonce: nonce, + playUri: playUri, }); }); }