fix: Infinite redirect loop on return from Slack auth without logged in session

This commit is contained in:
Tom Moor
2024-05-15 20:13:07 -04:00
parent bb69e891a4
commit 9622452b5d
2 changed files with 18 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
import Router from "koa-router"; import Router from "koa-router";
import find from "lodash/find"; import find from "lodash/find";
import { IntegrationService, IntegrationType } from "@shared/types"; import { IntegrationService, IntegrationType } from "@shared/types";
import { parseDomain } from "@shared/utils/domains";
import Logger from "@server/logging/Logger"; import Logger from "@server/logging/Logger";
import auth from "@server/middlewares/authentication"; import auth from "@server/middlewares/authentication";
import { transaction } from "@server/middlewares/transaction"; import { transaction } from "@server/middlewares/transaction";
@@ -51,12 +52,14 @@ router.get(
rejectOnEmpty: true, rejectOnEmpty: true,
transaction, transaction,
}); });
return ctx.redirectOnClient( return parseDomain(ctx.host).teamSubdomain === team.subdomain
GitHubUtils.callbackUrl({ ? ctx.redirect("/")
baseUrl: team.url, : ctx.redirectOnClient(
params: ctx.request.querystring, GitHubUtils.callbackUrl({
}) baseUrl: team.url,
); params: ctx.request.querystring,
})
);
} catch (err) { } catch (err) {
Logger.error(`Error fetching team for teamId: ${teamId}!`, err); Logger.error(`Error fetching team for teamId: ${teamId}!`, err);
return ctx.redirect(GitHubUtils.errorUrl("unauthenticated")); return ctx.redirect(GitHubUtils.errorUrl("unauthenticated"));

View File

@@ -4,6 +4,7 @@ import Router from "koa-router";
import { Profile } from "passport"; import { Profile } from "passport";
import { Strategy as SlackStrategy } from "passport-slack-oauth2"; import { Strategy as SlackStrategy } from "passport-slack-oauth2";
import { IntegrationService, IntegrationType } from "@shared/types"; import { IntegrationService, IntegrationType } from "@shared/types";
import { parseDomain } from "@shared/utils/domains";
import accountProvisioner from "@server/commands/accountProvisioner"; import accountProvisioner from "@server/commands/accountProvisioner";
import { ValidationError } from "@server/errors"; import { ValidationError } from "@server/errors";
import auth from "@server/middlewares/authentication"; import auth from "@server/middlewares/authentication";
@@ -155,12 +156,14 @@ if (env.SLACK_CLIENT_ID && env.SLACK_CLIENT_SECRET) {
const team = await Team.findByPk(teamId, { const team = await Team.findByPk(teamId, {
rejectOnEmpty: true, rejectOnEmpty: true,
}); });
return ctx.redirectOnClient( return parseDomain(ctx.host).teamSubdomain === team.subdomain
SlackUtils.connectUrl({ ? ctx.redirect("/")
baseUrl: team.url, : ctx.redirectOnClient(
params: ctx.request.querystring, SlackUtils.connectUrl({
}) baseUrl: team.url,
); params: ctx.request.querystring,
})
);
} catch (err) { } catch (err) {
return ctx.redirect(SlackUtils.errorUrl("unauthenticated")); return ctx.redirect(SlackUtils.errorUrl("unauthenticated"));
} }