improvments
This commit is contained in:
parent
af4611ed29
commit
3f9659ef3c
10 changed files with 72 additions and 71 deletions
|
@ -7,7 +7,6 @@ import bodyParser = require('body-parser');
|
|||
import * as http from "http";
|
||||
import {MapController} from "./Controller/MapController";
|
||||
import {PrometheusController} from "./Controller/PrometheusController";
|
||||
import {AdminController} from "./Controller/AdminController";
|
||||
import {DebugController} from "./Controller/DebugController";
|
||||
|
||||
class App {
|
||||
|
@ -17,7 +16,6 @@ class App {
|
|||
public authenticateController: AuthenticateController;
|
||||
public mapController: MapController;
|
||||
public prometheusController: PrometheusController;
|
||||
private adminController: AdminController;
|
||||
private debugController: DebugController;
|
||||
|
||||
constructor() {
|
||||
|
@ -36,7 +34,6 @@ class App {
|
|||
this.authenticateController = new AuthenticateController(this.app);
|
||||
this.mapController = new MapController(this.app);
|
||||
this.prometheusController = new PrometheusController(this.app, this.ioSocketController);
|
||||
this.adminController = new AdminController(this.app);
|
||||
this.debugController = new DebugController(this.app, this.ioSocketController);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,14 @@ import { uuid } from 'uuidv4';
|
|||
import Axios from "axios";
|
||||
|
||||
export interface TokenInterface {
|
||||
name: string,
|
||||
userUuid: string
|
||||
}
|
||||
|
||||
interface AdminApiData {
|
||||
organizationSlug: string
|
||||
worldSlug: string
|
||||
roomSlug: string
|
||||
mapUrlStart: string
|
||||
userUuid: string
|
||||
}
|
||||
|
||||
|
@ -35,20 +42,20 @@ export class AuthenticateController {
|
|||
return res.status(401).send('No admin backoffice set!');
|
||||
}
|
||||
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||
const response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+organizationMemberToken,
|
||||
const data = await Axios.get(ADMIN_API_URL+'/api/login-url/'+organizationMemberToken,
|
||||
{ headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }
|
||||
);
|
||||
).then((res): AdminApiData => res.data);
|
||||
|
||||
userUuid = response.data.userUuid;
|
||||
mapUrlStart = response.data.mapUrlStart;
|
||||
newUrl = this.getNewUrlOnAdminAuth(response.data)
|
||||
userUuid = data.userUuid;
|
||||
mapUrlStart = data.mapUrlStart;
|
||||
newUrl = this.getNewUrlOnAdminAuth(data)
|
||||
} else {
|
||||
userUuid = uuid();
|
||||
mapUrlStart= URL_ROOM_STARTED;
|
||||
mapUrlStart = req.headers.host?.replace('api.', 'maps.') + URL_ROOM_STARTED;
|
||||
newUrl = null;
|
||||
}
|
||||
|
||||
const authToken = Jwt.sign({userUuid: userUuid} as TokenInterface, SECRET_KEY, {expiresIn: '24h'});
|
||||
const authToken = Jwt.sign({userUuid: userUuid}, SECRET_KEY, {expiresIn: '24h'});
|
||||
return res.status(OK).send({
|
||||
authToken,
|
||||
userUuid,
|
||||
|
@ -64,7 +71,7 @@ export class AuthenticateController {
|
|||
});
|
||||
}
|
||||
|
||||
getNewUrlOnAdminAuth(data:any): string {
|
||||
private getNewUrlOnAdminAuth(data:AdminApiData): string {
|
||||
const organizationSlug = data.organizationSlug;
|
||||
const worldSlug = data.worldSlug;
|
||||
const roomSlug = data.roomSlug;
|
||||
|
|
|
@ -121,18 +121,19 @@ export class IoSocketController {
|
|||
return next(new Error('Authentication error'));
|
||||
}
|
||||
Jwt.verify(socket.handshake.query.token, SECRET_KEY, (err: JsonWebTokenError, tokenDecoded: object) => {
|
||||
const tokenInterface = tokenDecoded as TokenInterface;
|
||||
if (err) {
|
||||
console.error('An authentication error happened, invalid JsonWebToken.', err);
|
||||
return next(new Error('Authentication error'));
|
||||
}
|
||||
|
||||
if (!this.isValidToken(tokenDecoded)) {
|
||||
if (!this.isValidToken(tokenInterface)) {
|
||||
return next(new Error('Authentication error, invalid token structure'));
|
||||
}
|
||||
|
||||
(socket as ExSocketInterface).token = socket.handshake.query.token;
|
||||
(socket as ExSocketInterface).userId = this.nextUserId;
|
||||
(socket as ExSocketInterface).userUuid = tokenDecoded.userUuid;
|
||||
(socket as ExSocketInterface).userUuid = tokenInterface.userUuid;
|
||||
this.nextUserId++;
|
||||
next();
|
||||
});
|
||||
|
@ -141,11 +142,8 @@ export class IoSocketController {
|
|||
this.ioConnection();
|
||||
}
|
||||
|
||||
private isValidToken(token: object): token is TokenInterface {
|
||||
if (typeof((token as TokenInterface).userUuid) !== 'string') {
|
||||
return false;
|
||||
}
|
||||
if (typeof((token as TokenInterface).name) !== 'string') {
|
||||
private isValidToken(token: TokenInterface): boolean {
|
||||
if (typeof(token.userUuid) !== 'string') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -3,6 +3,7 @@ import {Application, Request, Response} from "express";
|
|||
import {OK} from "http-status-codes";
|
||||
import {URL_ROOM_STARTED} from "../Enum/EnvironmentVariable";
|
||||
|
||||
//todo: delete this
|
||||
export class MapController {
|
||||
App: Application;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {Socket} from "socket.io";
|
||||
import {PointInterface} from "./PointInterface";
|
||||
import {Identificable} from "./Identificable";
|
||||
import {TokenInterface} from "../../Controller/AuthenticateController";
|
||||
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
||||
import {BatchMessage, SubMessage} from "../../Messages/generated/messages_pb";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue