From 5435ee884680672de9263a8360c3a55d5a9247ed Mon Sep 17 00:00:00 2001 From: Harhio Date: Tue, 17 Dec 2024 13:12:14 +0200 Subject: [PATCH 1/2] DT-6631 fix localhost login --- server/auth/Strategy.js | 7 +++++++ src/setupProxy.js | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/server/auth/Strategy.js b/server/auth/Strategy.js index 580fb7de..cec6c8c9 100644 --- a/server/auth/Strategy.js +++ b/server/auth/Strategy.js @@ -176,6 +176,13 @@ OICStrategy.prototype.createAuthUrl = function (redirectUri, lang, ssoToken) { OICStrategy.prototype.createRedirectUrl = function (req) { const host = req.headers['x-forwarded-host'] || req.headers.host; + if ( + process.env.NODE_ENV === "local" && + req.headers.host === "localhost:3001" + ) { + return `http://${host}${this.callbackPath}`.replace("3001", "3000"); + } + if (req.secure) { return `https://${host}${this.callbackPath}`; } diff --git a/src/setupProxy.js b/src/setupProxy.js index 3ecf4adf..75c5e9e8 100644 --- a/src/setupProxy.js +++ b/src/setupProxy.js @@ -14,6 +14,17 @@ module.exports = function (app) { createProxyMiddleware({ target: 'http://localhost:3001', changeOrigin: true, + onProxyRes: function (proxyRes) { + if (process.env.NODE_ENV === "development" && + proxyRes.headers.location === "http://localhost:3000/" && + proxyRes.headers["set-cookie"] !== undefined) { + const cookies = proxyRes.headers["set-cookie"].map( + // get browser to set cookie for testing + (cookie) => cookie.replace("SameSite=None", "SameSite=Strict; Secure") + ); + proxyRes.headers["set-cookie"] = cookies; + } + }, }), ); app.use( @@ -35,6 +46,7 @@ module.exports = function (app) { createProxyMiddleware({ target: 'http://localhost:3001', changeOrigin: true, + hostRewrite: process.env.NODE_ENV === "development", }) ) app.use( From 01d6043739134594054a506c058b44552ddc6949 Mon Sep 17 00:00:00 2001 From: Harhio Date: Tue, 17 Dec 2024 14:12:45 +0200 Subject: [PATCH 2/2] DT-6631 fix hsl login --- src/setupProxy.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/setupProxy.js b/src/setupProxy.js index 75c5e9e8..1e154846 100644 --- a/src/setupProxy.js +++ b/src/setupProxy.js @@ -1,12 +1,29 @@ /* eslint-disable */ const { createProxyMiddleware } = require('http-proxy-middleware'); +const setLocalhostCookies = proxyRes => { + if ( + process.env.NODE_ENV === 'development' && + proxyRes.headers.location === 'http://localhost:3000/' && + proxyRes.headers['set-cookie'] !== undefined + ) { + const cookies = proxyRes.headers['set-cookie'].map( + // get browser to set cookie for testing + cookie => cookie.replace('SameSite=None', 'SameSite=Strict; Secure'), + ); + proxyRes.headers["set-cookie"] = cookies; + } +}; + module.exports = function (app) { app.use( '/oid_callback', createProxyMiddleware({ target: 'http://localhost:3001', changeOrigin: true, + onProxyRes: function (proxyRes) { + setLocalhostCookies(proxyRes); + }, }), ); app.use( @@ -15,15 +32,7 @@ module.exports = function (app) { target: 'http://localhost:3001', changeOrigin: true, onProxyRes: function (proxyRes) { - if (process.env.NODE_ENV === "development" && - proxyRes.headers.location === "http://localhost:3000/" && - proxyRes.headers["set-cookie"] !== undefined) { - const cookies = proxyRes.headers["set-cookie"].map( - // get browser to set cookie for testing - (cookie) => cookie.replace("SameSite=None", "SameSite=Strict; Secure") - ); - proxyRes.headers["set-cookie"] = cookies; - } + setLocalhostCookies(proxyRes); }, }), );