Skip to content

Commit c09dda4

Browse files
derive org from scim token
1 parent e0b9f02 commit c09dda4

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

packages/web/src/ee/features/scim/withScimAuth.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { __unsafePrisma } from "@/prisma";
22
import { hasEntitlement } from "@/lib/entitlements";
3-
import { SINGLE_TENANT_ORG_ID } from "@/lib/constants";
43
import { hashSecret, SCIM_TOKEN_PREFIX, createLogger } from "@sourcebot/shared";
54
import { Org, PrismaClient } from "@sourcebot/db";
65
import { NextRequest } from "next/server";
@@ -10,8 +9,6 @@ const logger = createLogger('scim-auth');
109

1110
export type ScimAuthContext = {
1211
org: Org;
13-
// SCIM acts on behalf of the IdP integration for the whole org — there is
14-
// no user, so we use the unscoped client rather than the user-scoped one.
1512
prisma: PrismaClient;
1613
};
1714

@@ -43,6 +40,7 @@ export const withScimAuth = async (
4340

4441
const scimToken = await __unsafePrisma.scimToken.findUnique({
4542
where: { hash: hashSecret(secret) },
43+
include: { org: true },
4644
});
4745
if (!scimToken) {
4846
return scimError(401, "Invalid SCIM token");
@@ -54,12 +52,6 @@ export const withScimAuth = async (
5452
return scimError(403, "SCIM provisioning is not available in your current plan");
5553
}
5654

57-
const org = await __unsafePrisma.org.findUnique({
58-
where: { id: SINGLE_TENANT_ORG_ID },
59-
});
60-
if (!org) {
61-
return scimError(500, "Organization not found");
62-
}
6355

6456
// Best-effort usage tracking; never block the request on it.
6557
__unsafePrisma.scimToken.update({
@@ -68,7 +60,10 @@ export const withScimAuth = async (
6860
}).catch(() => { /* ignore */ });
6961

7062
try {
71-
return await fn({ org, prisma: __unsafePrisma });
63+
return await fn({
64+
org: scimToken.org,
65+
prisma: __unsafePrisma
66+
});
7267
} catch (error) {
7368
logger.error(`Unhandled SCIM error: ${error instanceof Error ? error.message : String(error)}`);
7469
return scimError(500, "Internal server error");

0 commit comments

Comments
 (0)