Add play uri for login and register in hydra (#1421)

Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com>
This commit is contained in:
grégoire parant 2021-09-08 13:39:46 +02:00 committed by GitHub
parent f60678478b
commit 6cf86ec8dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 8 deletions

View file

@ -22,3 +22,5 @@ RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^[_@]/" "/index.html" [L] RewriteRule "^[_@]/" "/index.html" [L]
RewriteRule "^register/" "/index.html" [L] RewriteRule "^register/" "/index.html" [L]
RewriteRule "^login" "/index.html" [L]
RewriteRule "^jwt/" "/index.html" [L]

View file

@ -45,7 +45,7 @@ class ConnectionManager {
loginSceneVisibleIframeStore.set(false); loginSceneVisibleIframeStore.set(false);
return null; 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); window.location.assign(redirectUrl);
return redirectUrl; return redirectUrl;
} }
@ -76,10 +76,9 @@ class ConnectionManager {
this.connexionType = connexionType; this.connexionType = connexionType;
this._currentRoom = null; this._currentRoom = null;
if (connexionType === GameConnexionTypes.login) { 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())); 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) { } else if (connexionType === GameConnexionTypes.jwt) {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code"); const code = urlParams.get("code");
@ -91,13 +90,14 @@ class ConnectionManager {
throw "No Auth code provided"; throw "No Auth code provided";
} }
localUserStore.setCode(code); localUserStore.setCode(code);
this._currentRoom = await Room.createRoom(new URL(localUserStore.getLastRoomUrl()));
try { try {
await this.checkAuthUserConnexion(); await this.checkAuthUserConnexion();
} catch (err) { } catch (err) {
console.error(err); console.error(err);
this.loadOpenIDScreen(); 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); urlManager.pushRoomIdToUrl(this._currentRoom);
} else if (connexionType === GameConnexionTypes.register) { } else if (connexionType === GameConnexionTypes.register) {
//@deprecated //@deprecated

View file

@ -27,13 +27,17 @@ export class AuthenticateController extends BaseController {
console.warn("/message request was aborted"); console.warn("/message request was aborted");
}); });
const { nonce, state } = parse(req.getQuery()); const { nonce, state, playUri } = parse(req.getQuery());
if (!state || !nonce) { if (!state || !nonce) {
res.writeStatus("400 Unauthorized").end("missing state and nonce URL parameters"); res.writeStatus("400 Unauthorized").end("missing state and nonce URL parameters");
return; return;
} }
try { 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.writeStatus("302");
res.writeHeader("Location", loginUri); res.writeHeader("Location", loginUri);
return res.end(); return res.end();

View file

@ -20,13 +20,14 @@ class OpenIDClient {
return this.issuerPromise; return this.issuerPromise;
} }
public authorizationUrl(state: string, nonce: string) { public authorizationUrl(state: string, nonce: string, playUri?: string) {
return this.initClient().then((client) => { return this.initClient().then((client) => {
return client.authorizationUrl({ return client.authorizationUrl({
scope: "openid email", scope: "openid email",
prompt: "login", prompt: "login",
state: state, state: state,
nonce: nonce, nonce: nonce,
playUri: playUri,
}); });
}); });
} }