Merge pull request #1564 from thecodingmachine/HotFixAuthenticationManager

Hot fix authentication manager
This commit is contained in:
grégoire parant 2021-11-16 15:17:46 +01:00 committed by GitHub
commit 7d73ca321d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 15 deletions

View File

@ -40,7 +40,9 @@
}) })
function copyLink() { function copyLink() {
HTMLShareLink.select(); const input: HTMLInputElement = document.getElementById('input-share-link') as HTMLInputElement;
input.focus();
input.select();
document.execCommand('copy'); document.execCommand('copy');
} }
@ -59,12 +61,12 @@
<div class="about-room-main"> <div class="about-room-main">
<section class="share-url not-mobile"> <section class="share-url not-mobile">
<h3>Share the link of the room !</h3> <h3>Share the link of the room !</h3>
<input type="text" readonly bind:this={HTMLShareLink} value={location.toString()}> <input type="text" readonly id="input-share-link" bind:this={HTMLShareLink} value={location.toString()}>
<button type="button" class="nes-btn is-primary" on:click={copyLink}>Copy</button> <button type="button" class="nes-btn is-primary" on:click={copyLink}>Copy</button>
</section> </section>
<section class="is-mobile"> <section class="is-mobile">
<h3>Share the link of the room !</h3> <h3>Share the link of the room !</h3>
<input type="hidden" readonly bind:this={HTMLShareLink} value={location.toString()}> <input type="hidden" readonly id="input-share-link" bind:this={HTMLShareLink} value={location.toString()}>
<button type="button" class="nes-btn is-primary" on:click={shareLink}>Share</button> <button type="button" class="nes-btn is-primary" on:click={shareLink}>Share</button>
</section> </section>
<h2>Information on the map</h2> <h2>Information on the map</h2>

View File

@ -2,7 +2,9 @@
let HTMLShareLink: HTMLInputElement; let HTMLShareLink: HTMLInputElement;
function copyLink() { function copyLink() {
HTMLShareLink.select(); const input: HTMLInputElement = document.getElementById('input-share-link') as HTMLInputElement;
input.focus();
input.select();
document.execCommand('copy'); document.execCommand('copy');
} }
@ -22,12 +24,12 @@
<section class="container-overflow"> <section class="container-overflow">
<section class="share-url not-mobile"> <section class="share-url not-mobile">
<h3>Share the link of the room !</h3> <h3>Share the link of the room !</h3>
<input type="text" readonly bind:this={HTMLShareLink} value={location.toString()}> <input type="text" readonly id="input-share-link" bind:this={HTMLShareLink} value={location.toString()}>
<button type="button" class="nes-btn is-primary" on:click={copyLink}>Copy</button> <button type="button" class="nes-btn is-primary" on:click={copyLink}>Copy</button>
</section> </section>
<section class="is-mobile"> <section class="is-mobile">
<h3>Share the link of the room !</h3> <h3>Share the link of the room !</h3>
<input type="hidden" readonly bind:this={HTMLShareLink} value={location.toString()}> <input type="hidden" readonly id="input-share-link" bind:this={HTMLShareLink} value={location.toString()}>
<button type="button" class="nes-btn is-primary" on:click={shareLink}>Share</button> <button type="button" class="nes-btn is-primary" on:click={shareLink}>Share</button>
</section> </section>
</section> </section>

View File

@ -226,7 +226,7 @@ class ConnectionManager {
public async anonymousLogin(isBenchmark: boolean = false): Promise<void> { public async anonymousLogin(isBenchmark: boolean = false): Promise<void> {
const data = await Axios.post(`${PUSHER_URL}/anonymLogin`).then((res) => res.data); 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; this.authToken = data.authToken;
if (!isBenchmark) { if (!isBenchmark) {
// In benchmark, we don't have a local storage. // In benchmark, we don't have a local storage.

View File

@ -63,25 +63,30 @@ export class AuthenticateController extends BaseController {
if (token != undefined) { if (token != undefined) {
try { try {
const authTokenData: AuthTokenData = jwtTokenManager.verifyJWTToken(token as string, false); const authTokenData: AuthTokenData = jwtTokenManager.verifyJWTToken(token as string, false);
if (authTokenData.accessToken == undefined) {
//if not nonce and code, user connected in anonymous //Get user data from Admin Back Office
//get data with identifier and return token //This is very important to create User Local in LocalStorage in WorkAdventure
if (!code && !nonce) { const resUserData = await this.getUserByUserIdentifier(
const data = await this.getUserByUserIdentifier(
authTokenData.identifier, authTokenData.identifier,
playUri as string, playUri as string,
IPAddress IPAddress
); );
if (authTokenData.accessToken == undefined) {
//if not nonce and code, user connected in anonymous
//get data with identifier and return token
if (!code && !nonce) {
res.writeStatus("200"); res.writeStatus("200");
this.addCorsHeaders(res); 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"); throw Error("Token cannot to be check on Hydra");
} }
const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken); const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken);
res.writeStatus("200"); res.writeStatus("200");
this.addCorsHeaders(res); this.addCorsHeaders(res);
return res.end(JSON.stringify({ ...resCheckTokenAuth, authToken: token })); return res.end(JSON.stringify({ ...resCheckTokenAuth, ...resUserData, authToken: token }));
} catch (err) { } catch (err) {
console.info("User was not connected", err); console.info("User was not connected", err);
} }
@ -261,7 +266,14 @@ export class AuthenticateController extends BaseController {
playUri: string, playUri: string,
IPAddress: string IPAddress: string
): Promise<FetchMemberDataByUuidResponse | object> { ): Promise<FetchMemberDataByUuidResponse | object> {
let data: FetchMemberDataByUuidResponse | object = {}; let data: FetchMemberDataByUuidResponse = {
email: email,
userUuid: email,
tags: [],
messages: [],
visitCardUrl: null,
textures: [],
};
try { try {
data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress); data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress);
} catch (err) { } catch (err) {

View File

@ -189,6 +189,7 @@ export class IoSocketController {
let memberTextures: CharacterTexture[] = []; let memberTextures: CharacterTexture[] = [];
const room = await socketManager.getOrCreateRoom(roomId); const room = await socketManager.getOrCreateRoom(roomId);
let userData: FetchMemberDataByUuidResponse = { let userData: FetchMemberDataByUuidResponse = {
email: userIdentifier,
userUuid: userIdentifier, userUuid: userIdentifier,
tags: [], tags: [],
visitCardUrl: null, visitCardUrl: null,

View File

@ -22,6 +22,7 @@ export interface AdminBannedData {
} }
export interface FetchMemberDataByUuidResponse { export interface FetchMemberDataByUuidResponse {
email: string;
userUuid: string; userUuid: string;
tags: string[]; tags: string[];
visitCardUrl: string | null; visitCardUrl: string | null;