Skip to content

Commit

Permalink
Should fix issue with app having to authorize it's own routes
Browse files Browse the repository at this point in the history
  • Loading branch information
PixNyb committed Jan 23, 2025
1 parent c3470db commit 25d662b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/middlewares/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const strategies = require("../strategies");

module.exports = (req, res) => {
const path = (req.forwardedUri || req.url).split("?")[0];
const applicationRoutes = [
let applicationRoutes = [
`/healthz`,
`${AUTH_PREFIX}/`,
`${AUTH_PREFIX}/refresh`,
Expand All @@ -22,11 +22,15 @@ module.exports = (req, res) => {
`${AUTH_PREFIX}/remove-cookies`,
`${PROMETHEUS_PREFIX}/metrics`
]
const providerRoutes = Object.values(strategies).reduce((acc, strategy) => {
if (strategy.params.loginURL) acc.push(strategy.params.loginURL);
if (strategy.params.callbackURL) acc.push(strategy.params.callbackURL);
return acc;
}, []);
let providerRoutes = [];
Object.entries(strategies).forEach(([, strategyConfig]) => {
const { loginURL, callbackURL } = strategyConfig.params;
providerRoutes.push(loginURL);
providerRoutes.push(callbackURL);
});

applicationRoutes = [...new Set(applicationRoutes)];
providerRoutes = [...new Set(providerRoutes)];

if (providerRoutes.includes(path) || applicationRoutes.includes(path)) {
return res.sendStatus(200);
Expand Down

0 comments on commit 25d662b

Please sign in to comment.