Skip to content

Commit

Permalink
Merge pull request #492 from HSLdevcom/DT-6631
Browse files Browse the repository at this point in the history
DT-6631 fix localhost login
  • Loading branch information
Antiik91 authored Dec 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 2e6fed1 + 01d6043 commit 7f14109
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/auth/Strategy.js
Original file line number Diff line number Diff line change
@@ -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}`;
}
21 changes: 21 additions & 0 deletions src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
/* 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(
'/oid_waltti_callback',
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(

0 comments on commit 7f14109

Please sign in to comment.