Working on integration of the woka-list with the new admin endpoint.

This commit is contained in:
David Négrier
2022-02-24 21:09:19 +01:00
parent 0543232bc3
commit da469b64d2
14 changed files with 79 additions and 68 deletions
@@ -68,7 +68,7 @@ export class AuthenticateController extends BaseHttpController {
);
res.status(302);
res.setHeader("Location", loginUri);
return res;
return res.send("");
} catch (e) {
console.error("openIDLogin => e", e);
this.castErrorToResponse(e, res);
+19 -7
View File
@@ -1,11 +1,16 @@
import { BaseHttpController } from "./BaseHttpController";
import { wokaService } from "../Services/WokaService";
import * as tg from "generic-type-guard";
import { jwtTokenManager } from "../Services/JWTTokenManager";
export class WokaListController extends BaseHttpController {
routes() {
this.app.options("/woka/list/:roomUrl", {}, async (req, res) => {
res.status(200).send("");
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.app.get("/woka/list/:roomId", {}, async (req, res) => {
this.app.get("/woka/list/:roomUrl", {}, async (req, res) => {
const token = req.header("Authorization");
if (!token) {
@@ -13,12 +18,19 @@ export class WokaListController extends BaseHttpController {
return;
}
try {
const jwtData = jwtTokenManager.verifyJWTToken(token);
// Let's set the "uuid" param
req.params["uuid"] = jwtData.identifier;
} catch (e) {
console.error("Connection refused for token: " + token, e);
res.status(401).send("Invalid token sent");
return;
}
const isParameters = new tg.IsInterface()
.withProperties({
roomId: tg.isString,
})
.withOptionalProperties({
messages: tg.isArray(tg.isUnknown),
roomUrl: tg.isString,
})
.get();
@@ -26,8 +38,8 @@ export class WokaListController extends BaseHttpController {
return res.status(400).send("Unknown parameters");
}
const roomId = req.path_parameters.roomId;
const wokaList = await wokaService.getWokaList(roomId, token);
const roomUrl = decodeURIComponent(req.path_parameters.roomUrl);
const wokaList = await wokaService.getWokaList(roomUrl, req.params["uuid"]);
if (!wokaList) {
return res.status(500).send("Error on getting woka list");
+1
View File
@@ -10,6 +10,7 @@ export function cors(req: Request, res: Response, next?: MiddlewareNext): Middle
);
res.setHeader("access-control-allow-methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
res.setHeader("access-control-allow-origin", FRONT_URL);
res.setHeader("access-control-allow-credentials", "true");
if (next) {
next();
+6 -2
View File
@@ -7,10 +7,14 @@ class AdminWokaService implements WokaServiceInterface {
/**
* Returns the list of all available Wokas for the current user.
*/
getWokaList(roomId: string, token: string): Promise<WokaList | undefined> {
getWokaList(roomUrl: string, token: string): Promise<WokaList | undefined> {
return axios
.get(`${ADMIN_API_URL}/api/woka/list/${roomId}/${token}`, {
.get(`${ADMIN_API_URL}/api/woka/list`, {
headers: { Authorization: `${ADMIN_API_TOKEN}` },
params: {
roomUrl,
uuid: token,
},
})
.then((res) => {
if (isWokaList(res.data)) {