From 9073024b1d69b993475a61a5b13669f5d1e7d50a Mon Sep 17 00:00:00 2001 From: Ludwig Behm Date: Sat, 12 Feb 2022 22:19:48 +0100 Subject: [PATCH 1/2] pusher: add missing Content-Type header for json responses --- pusher/src/Controller/AuthenticateController.ts | 5 +++++ pusher/src/Controller/MapController.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index fe80eafa..fff76c40 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -79,6 +79,7 @@ export class AuthenticateController extends BaseController { if (!code && !nonce) { res.writeStatus("200"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); return res.end(JSON.stringify({ ...resUserData, authToken: token })); } console.error("Token cannot to be check on OpenId provider"); @@ -91,6 +92,7 @@ export class AuthenticateController extends BaseController { const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken); res.writeStatus("200"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); return res.end(JSON.stringify({ ...resCheckTokenAuth, ...resUserData, authToken: token })); } catch (err) { console.info("User was not connected", err); @@ -121,6 +123,7 @@ export class AuthenticateController extends BaseController { res.writeStatus("200"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); return res.end(JSON.stringify({ ...data, authToken })); } catch (e) { console.error("openIDCallback => ERROR", e); @@ -183,6 +186,7 @@ export class AuthenticateController extends BaseController { const authToken = jwtTokenManager.createAuthToken(email || userUuid); res.writeStatus("200 OK"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); res.end( JSON.stringify({ authToken, @@ -222,6 +226,7 @@ export class AuthenticateController extends BaseController { const authToken = jwtTokenManager.createAuthToken(userUuid); res.writeStatus("200 OK"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); res.end( JSON.stringify({ authToken, diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 00936b44..9dd2aaf8 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -47,6 +47,7 @@ export class MapController extends BaseController { if (!match) { res.writeStatus("404 Not Found"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); res.end(JSON.stringify({})); return; } @@ -55,6 +56,7 @@ export class MapController extends BaseController { res.writeStatus("200 OK"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); res.end( JSON.stringify({ mapUrl, @@ -106,6 +108,7 @@ export class MapController extends BaseController { res.writeStatus("200 OK"); this.addCorsHeaders(res); + res.writeHeader('Content-Type', 'application/json'); res.end(JSON.stringify(mapDetails)); } catch (e) { this.errorToResponse(e, res); From 4bcdbcb1bd6b11e42a60bd47fe6b0cf69f05228a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 15 Feb 2022 09:15:41 +0100 Subject: [PATCH 2/2] Fixing linting --- pusher/src/Controller/AuthenticateController.ts | 10 +++++----- pusher/src/Controller/MapController.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index fff76c40..89d3adf3 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -79,7 +79,7 @@ export class AuthenticateController extends BaseController { if (!code && !nonce) { res.writeStatus("200"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); return res.end(JSON.stringify({ ...resUserData, authToken: token })); } console.error("Token cannot to be check on OpenId provider"); @@ -92,7 +92,7 @@ export class AuthenticateController extends BaseController { const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken); res.writeStatus("200"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); return res.end(JSON.stringify({ ...resCheckTokenAuth, ...resUserData, authToken: token })); } catch (err) { console.info("User was not connected", err); @@ -123,7 +123,7 @@ export class AuthenticateController extends BaseController { res.writeStatus("200"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); return res.end(JSON.stringify({ ...data, authToken })); } catch (e) { console.error("openIDCallback => ERROR", e); @@ -186,7 +186,7 @@ export class AuthenticateController extends BaseController { const authToken = jwtTokenManager.createAuthToken(email || userUuid); res.writeStatus("200 OK"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); res.end( JSON.stringify({ authToken, @@ -226,7 +226,7 @@ export class AuthenticateController extends BaseController { const authToken = jwtTokenManager.createAuthToken(userUuid); res.writeStatus("200 OK"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); res.end( JSON.stringify({ authToken, diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 9dd2aaf8..eae205f9 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -47,7 +47,7 @@ export class MapController extends BaseController { if (!match) { res.writeStatus("404 Not Found"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); res.end(JSON.stringify({})); return; } @@ -56,7 +56,7 @@ export class MapController extends BaseController { res.writeStatus("200 OK"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); res.end( JSON.stringify({ mapUrl, @@ -108,7 +108,7 @@ export class MapController extends BaseController { res.writeStatus("200 OK"); this.addCorsHeaders(res); - res.writeHeader('Content-Type', 'application/json'); + res.writeHeader("Content-Type", "application/json"); res.end(JSON.stringify(mapDetails)); } catch (e) { this.errorToResponse(e, res);