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..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( @@ -14,6 +31,9 @@ module.exports = function (app) { createProxyMiddleware({ target: 'http://localhost:3001', changeOrigin: true, + onProxyRes: function (proxyRes) { + setLocalhostCookies(proxyRes); + }, }), ); app.use( @@ -35,6 +55,7 @@ module.exports = function (app) { createProxyMiddleware({ target: 'http://localhost:3001', changeOrigin: true, + hostRewrite: process.env.NODE_ENV === "development", }) ) app.use(