@open-mercato/enterprise 0.10.1-develop.7809.1.ea24461aeb → 0.10.1-develop.7813.1.83931e7add
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/sso/api/scim/context.js +17 -1
- package/dist/modules/sso/api/scim/context.js.map +2 -2
- package/dist/modules/sso/api/scim/rate-limit.js +85 -0
- package/dist/modules/sso/api/scim/rate-limit.js.map +7 -0
- package/dist/modules/sso/api/scim/v2/ServiceProviderConfig/route.js +10 -2
- package/dist/modules/sso/api/scim/v2/ServiceProviderConfig/route.js.map +2 -2
- package/dist/modules/sso/api/scim/v2/Users/[id]/route.js +11 -3
- package/dist/modules/sso/api/scim/v2/Users/[id]/route.js.map +2 -2
- package/dist/modules/sso/api/scim/v2/Users/route.js +8 -2
- package/dist/modules/sso/api/scim/v2/Users/route.js.map +2 -2
- package/dist/modules/sso/data/entities.js +4 -0
- package/dist/modules/sso/data/entities.js.map +2 -2
- package/dist/modules/sso/lib/scim-admission-cache.js +28 -0
- package/dist/modules/sso/lib/scim-admission-cache.js.map +7 -0
- package/dist/modules/sso/migrations/Migration20261029160000_scim_token_lookup_hash.js +15 -0
- package/dist/modules/sso/migrations/Migration20261029160000_scim_token_lookup_hash.js.map +7 -0
- package/dist/modules/sso/services/scimTokenService.js +76 -14
- package/dist/modules/sso/services/scimTokenService.js.map +2 -2
- package/package.json +9 -9
- package/src/modules/sso/api/scim/context.ts +18 -2
- package/src/modules/sso/api/scim/rate-limit.ts +90 -0
- package/src/modules/sso/api/scim/v2/ServiceProviderConfig/route.ts +10 -2
- package/src/modules/sso/api/scim/v2/Users/[id]/route.ts +7 -0
- package/src/modules/sso/api/scim/v2/Users/route.ts +5 -0
- package/src/modules/sso/data/entities.ts +4 -0
- package/src/modules/sso/lib/scim-admission-cache.ts +26 -0
- package/src/modules/sso/migrations/.snapshot-open-mercato.json +19 -0
- package/src/modules/sso/migrations/Migration20261029160000_scim_token_lookup_hash.ts +13 -0
- package/src/modules/sso/services/scimTokenService.ts +72 -16
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[build:enterprise] found
|
|
1
|
+
[build:enterprise] found 707 entry points
|
|
2
2
|
[build:enterprise] built successfully
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
2
|
+
import { ScimTokenError } from "../../services/scimTokenService.js";
|
|
3
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
4
|
+
import { RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK } from "@open-mercato/shared/lib/ratelimit/helpers";
|
|
2
5
|
import { SsoConfig } from "../../data/entities.js";
|
|
3
6
|
import { buildScimError, scimJson } from "../../lib/scim-response.js";
|
|
7
|
+
import { checkScimRateLimit } from "./rate-limit.js";
|
|
4
8
|
async function resolveScimContext(req) {
|
|
9
|
+
const rateLimitError = await checkScimRateLimit(req);
|
|
10
|
+
if (rateLimitError) return { ok: false, response: rateLimitError };
|
|
5
11
|
const authHeader = req.headers.get("authorization");
|
|
6
12
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
7
13
|
return {
|
|
@@ -21,7 +27,17 @@ async function resolveScimContext(req) {
|
|
|
21
27
|
}
|
|
22
28
|
const container = await createRequestContainer();
|
|
23
29
|
const scimTokenService = container.resolve("scimTokenService");
|
|
24
|
-
|
|
30
|
+
let verified;
|
|
31
|
+
try {
|
|
32
|
+
verified = await scimTokenService.verifyToken(rawToken);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!(error instanceof ScimTokenError) || error.statusCode !== 503) throw error;
|
|
35
|
+
const { translate } = await resolveTranslations();
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
response: scimJson(buildScimError(503, translate(RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK)), 503)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
25
41
|
if (!verified) {
|
|
26
42
|
return {
|
|
27
43
|
ok: false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/sso/api/scim/context.ts"],
|
|
4
|
-
"sourcesContent": ["import { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { ScimTokenService } from '../../services/scimTokenService'\nimport { SsoConfig } from '../../data/entities'\nimport { buildScimError, scimJson } from '../../lib/scim-response'\nimport type { EntityManager } from '@mikro-orm/postgresql'\n\nexport interface ScimScope {\n ssoConfigId: string\n organizationId: string\n tenantId: string | null\n config: SsoConfig\n}\n\nexport async function resolveScimContext(req: Request): Promise<\n | { ok: true; scope: ScimScope }\n | { ok: false; response: Response }\n> {\n const authHeader = req.headers.get('authorization')\n if (!authHeader || !authHeader.startsWith('Bearer ')) {\n return {\n ok: false,\n response: scimJson(\n buildScimError(401, 'Bearer token required'),\n 401,\n ),\n }\n }\n\n const rawToken = authHeader.slice(7)\n if (!rawToken) {\n return {\n ok: false,\n response: scimJson(buildScimError(401, 'Bearer token required'), 401),\n }\n }\n\n const container = await createRequestContainer()\n const scimTokenService = container.resolve<ScimTokenService>('scimTokenService')\n
|
|
5
|
-
"mappings": "AAAA,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { ScimTokenError, ScimTokenService } from '../../services/scimTokenService'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK } from '@open-mercato/shared/lib/ratelimit/helpers'\nimport { SsoConfig } from '../../data/entities'\nimport { buildScimError, scimJson } from '../../lib/scim-response'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { checkScimRateLimit } from './rate-limit'\n\nexport interface ScimScope {\n ssoConfigId: string\n organizationId: string\n tenantId: string | null\n config: SsoConfig\n}\n\nexport async function resolveScimContext(req: Request): Promise<\n | { ok: true; scope: ScimScope }\n | { ok: false; response: Response }\n> {\n const rateLimitError = await checkScimRateLimit(req)\n if (rateLimitError) return { ok: false, response: rateLimitError }\n\n const authHeader = req.headers.get('authorization')\n if (!authHeader || !authHeader.startsWith('Bearer ')) {\n return {\n ok: false,\n response: scimJson(\n buildScimError(401, 'Bearer token required'),\n 401,\n ),\n }\n }\n\n const rawToken = authHeader.slice(7)\n if (!rawToken) {\n return {\n ok: false,\n response: scimJson(buildScimError(401, 'Bearer token required'), 401),\n }\n }\n\n const container = await createRequestContainer()\n const scimTokenService = container.resolve<ScimTokenService>('scimTokenService')\n let verified: Awaited<ReturnType<ScimTokenService['verifyToken']>>\n try {\n verified = await scimTokenService.verifyToken(rawToken)\n } catch (error) {\n if (!(error instanceof ScimTokenError) || error.statusCode !== 503) throw error\n const { translate } = await resolveTranslations()\n return {\n ok: false,\n response: scimJson(buildScimError(503, translate(RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK)), 503),\n }\n }\n\n if (!verified) {\n return {\n ok: false,\n response: scimJson(buildScimError(401, 'Invalid or revoked token'), 401),\n }\n }\n\n const em = container.resolve<EntityManager>('em')\n const config = await em.findOne(SsoConfig, {\n id: verified.ssoConfigId,\n organizationId: verified.organizationId,\n deletedAt: null,\n })\n\n if (!config) {\n return {\n ok: false,\n response: scimJson(buildScimError(403, 'SSO configuration not found'), 403),\n }\n }\n\n if (!config.isActive) {\n return {\n ok: false,\n response: scimJson(buildScimError(403, 'SSO configuration is not active'), 403),\n }\n }\n\n if (config.jitEnabled) {\n return {\n ok: false,\n response: scimJson(buildScimError(403, 'SCIM provisioning is unavailable \u2014 JIT provisioning is enabled on this configuration'), 403),\n }\n }\n\n return {\n ok: true,\n scope: {\n ssoConfigId: config.id,\n organizationId: config.organizationId,\n tenantId: verified.tenantId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zE;AAAA,EACF;AAEA,QAAM,KAAK,UAAU,QAAuB,IAAI;AAChD,QAAM,SAAS,MAAM,GAAG,QAAQ,WAAW;AAAA,IACzC,IAAI,SAAS;AAAA,IACb,gBAAgB,SAAS;AAAA,IACzB,WAAW;AAAA,EACb,CAAC;AAED,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,UAAU,SAAS,eAAe,KAAK,6BAA6B,GAAG,GAAG;AAAA,IAC5E;AAAA,EACF;AAEA,MAAI,CAAC,OAAO,UAAU;AACpB,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,UAAU,SAAS,eAAe,KAAK,iCAAiC,GAAG,GAAG;AAAA,IAChF;AAAA,EACF;AAEA,MAAI,OAAO,YAAY;AACrB,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,UAAU,SAAS,eAAe,KAAK,2FAAsF,GAAG,GAAG;AAAA,IACrI;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,MACL,aAAa,OAAO;AAAA,MACpB,gBAAgB,OAAO;AAAA,MACvB,UAAU,SAAS;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
2
|
+
import { getCachedRateLimiterService } from "@open-mercato/core/bootstrap";
|
|
3
|
+
import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
|
|
4
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
5
|
+
import { readEndpointRateLimitConfig, readRateLimitConfig } from "@open-mercato/shared/lib/ratelimit/config";
|
|
6
|
+
import { getTelemetryRuntime } from "@open-mercato/shared/lib/telemetry/runtime";
|
|
7
|
+
import {
|
|
8
|
+
checkRateLimit,
|
|
9
|
+
getClientIp,
|
|
10
|
+
RATE_LIMIT_ERROR_KEY,
|
|
11
|
+
RATE_LIMIT_ERROR_FALLBACK,
|
|
12
|
+
RATE_LIMIT_FALLBACK_KEY,
|
|
13
|
+
RATE_LIMIT_UNAVAILABLE_KEY,
|
|
14
|
+
RATE_LIMIT_UNAVAILABLE_FALLBACK
|
|
15
|
+
} from "@open-mercato/shared/lib/ratelimit/helpers";
|
|
16
|
+
import { buildScimError, scimJson } from "../../lib/scim-response.js";
|
|
17
|
+
import { readScimAdmissionKey, scimAdmissionTokenKey, scimTokenLookupHash } from "../../lib/scim-admission-cache.js";
|
|
18
|
+
import { ScimToken } from "../../data/entities.js";
|
|
19
|
+
const admissions = /* @__PURE__ */ new WeakMap();
|
|
20
|
+
function checkScimRateLimit(req) {
|
|
21
|
+
const existing = admissions.get(req);
|
|
22
|
+
if (existing) return existing;
|
|
23
|
+
const admission = consumeScimRateLimit(req);
|
|
24
|
+
admissions.set(req, admission);
|
|
25
|
+
return admission;
|
|
26
|
+
}
|
|
27
|
+
async function consumeScimRateLimit(req) {
|
|
28
|
+
let limited = new Response(null, { status: 503 });
|
|
29
|
+
try {
|
|
30
|
+
if (!readRateLimitConfig().enabled) return null;
|
|
31
|
+
const limiter = getCachedRateLimiterService();
|
|
32
|
+
const config = readEndpointRateLimitConfig("SCIM", {
|
|
33
|
+
points: 10,
|
|
34
|
+
duration: 1,
|
|
35
|
+
keyPrefix: "sso-scim"
|
|
36
|
+
});
|
|
37
|
+
if (limiter) {
|
|
38
|
+
const key = await resolveScimRateLimitKey(req, getClientIp(req, limiter.trustProxyDepth));
|
|
39
|
+
limited = await checkRateLimit(limiter, config, key, RATE_LIMIT_ERROR_FALLBACK, { failClosed: true });
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
try {
|
|
43
|
+
getTelemetryRuntime()?.reportError(error, { module: "sso", code: "sso.scim_admission_unavailable" });
|
|
44
|
+
} catch {
|
|
45
|
+
return buildScimRateLimitResponse(new Response(null, { status: 503 }));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!limited) return null;
|
|
49
|
+
return buildScimRateLimitResponse(limited);
|
|
50
|
+
}
|
|
51
|
+
async function buildScimRateLimitResponse(limited) {
|
|
52
|
+
const { translate } = await resolveTranslations();
|
|
53
|
+
const detail = limited.status === 429 ? translate(RATE_LIMIT_ERROR_KEY, RATE_LIMIT_ERROR_FALLBACK) : translate(RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK);
|
|
54
|
+
const response = scimJson(buildScimError(limited.status, detail), limited.status);
|
|
55
|
+
limited.headers.forEach((value, name) => {
|
|
56
|
+
if (name !== "content-type") response.headers.set(name, value);
|
|
57
|
+
});
|
|
58
|
+
return response;
|
|
59
|
+
}
|
|
60
|
+
async function resolveScimRateLimitKey(req, clientIp) {
|
|
61
|
+
if (new URL(req.url).pathname.replace(/\/+$/, "").endsWith("/sso/scim/v2/ServiceProviderConfig")) {
|
|
62
|
+
return `discovery:${clientIp ?? RATE_LIMIT_FALLBACK_KEY}`;
|
|
63
|
+
}
|
|
64
|
+
const authorization = req.headers.get("authorization");
|
|
65
|
+
const rawToken = authorization?.startsWith("Bearer ") ? authorization.slice(7) : "";
|
|
66
|
+
if (/^omscim_[0-9a-f]{64}$/.test(rawToken)) {
|
|
67
|
+
const container = await createRequestContainer();
|
|
68
|
+
const cache = container.resolve("cache");
|
|
69
|
+
const verifiedKey = await readScimAdmissionKey(cache, rawToken);
|
|
70
|
+
if (verifiedKey) return verifiedKey;
|
|
71
|
+
const em = container.resolve("em");
|
|
72
|
+
const token = await findOneWithDecryption(em, ScimToken, {
|
|
73
|
+
tokenLookupHash: scimTokenLookupHash(rawToken),
|
|
74
|
+
isActive: true
|
|
75
|
+
}, { fields: ["id", "tenantId", "organizationId"] }).catch(() => {
|
|
76
|
+
throw new Error("[internal] SCIM fingerprint lookup unavailable");
|
|
77
|
+
});
|
|
78
|
+
if (token) return scimAdmissionTokenKey(token);
|
|
79
|
+
}
|
|
80
|
+
return clientIp ?? RATE_LIMIT_FALLBACK_KEY;
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
checkScimRateLimit
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/modules/sso/api/scim/rate-limit.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { CacheStrategy } from '@open-mercato/cache'\nimport { getCachedRateLimiterService } from '@open-mercato/core/bootstrap'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { readEndpointRateLimitConfig, readRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\nimport {\n checkRateLimit,\n getClientIp,\n RATE_LIMIT_ERROR_KEY,\n RATE_LIMIT_ERROR_FALLBACK,\n RATE_LIMIT_FALLBACK_KEY,\n RATE_LIMIT_UNAVAILABLE_KEY,\n RATE_LIMIT_UNAVAILABLE_FALLBACK,\n} from '@open-mercato/shared/lib/ratelimit/helpers'\nimport { buildScimError, scimJson } from '../../lib/scim-response'\nimport { readScimAdmissionKey, scimAdmissionTokenKey, scimTokenLookupHash } from '../../lib/scim-admission-cache'\nimport { ScimToken } from '../../data/entities'\n\nconst admissions = new WeakMap<Request, Promise<Response | null>>()\n\nexport function checkScimRateLimit(req: Request): Promise<Response | null> {\n const existing = admissions.get(req)\n if (existing) return existing\n const admission = consumeScimRateLimit(req)\n admissions.set(req, admission)\n return admission\n}\n\nasync function consumeScimRateLimit(req: Request): Promise<Response | null> {\n let limited: Response | null = new Response(null, { status: 503 })\n try {\n if (!readRateLimitConfig().enabled) return null\n const limiter = getCachedRateLimiterService()\n const config = readEndpointRateLimitConfig('SCIM', {\n points: 10,\n duration: 1,\n keyPrefix: 'sso-scim',\n })\n if (limiter) {\n const key = await resolveScimRateLimitKey(req, getClientIp(req, limiter.trustProxyDepth))\n limited = await checkRateLimit(limiter, config, key, RATE_LIMIT_ERROR_FALLBACK, { failClosed: true })\n }\n } catch (error) {\n try {\n getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_admission_unavailable' })\n } catch {\n return buildScimRateLimitResponse(new Response(null, { status: 503 }))\n }\n }\n if (!limited) return null\n return buildScimRateLimitResponse(limited)\n}\n\nasync function buildScimRateLimitResponse(limited: Response): Promise<Response> {\n const { translate } = await resolveTranslations()\n const detail = limited.status === 429\n ? translate(RATE_LIMIT_ERROR_KEY, RATE_LIMIT_ERROR_FALLBACK)\n : translate(RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK)\n const response = scimJson(buildScimError(limited.status, detail), limited.status)\n limited.headers.forEach((value, name) => {\n if (name !== 'content-type') response.headers.set(name, value)\n })\n return response\n}\n\nasync function resolveScimRateLimitKey(req: Request, clientIp: string | null): Promise<string> {\n if (new URL(req.url).pathname.replace(/\\/+$/, '').endsWith('/sso/scim/v2/ServiceProviderConfig')) {\n return `discovery:${clientIp ?? RATE_LIMIT_FALLBACK_KEY}`\n }\n const authorization = req.headers.get('authorization')\n const rawToken = authorization?.startsWith('Bearer ') ? authorization.slice(7) : ''\n if (/^omscim_[0-9a-f]{64}$/.test(rawToken)) {\n const container = await createRequestContainer()\n const cache = container.resolve<CacheStrategy>('cache')\n const verifiedKey = await readScimAdmissionKey(cache, rawToken)\n if (verifiedKey) return verifiedKey\n const em = container.resolve<EntityManager>('em')\n const token = await findOneWithDecryption(em, ScimToken, {\n tokenLookupHash: scimTokenLookupHash(rawToken),\n isActive: true,\n }, { fields: ['id', 'tenantId', 'organizationId'] }).catch(() => {\n throw new Error('[internal] SCIM fingerprint lookup unavailable')\n })\n if (token) return scimAdmissionTokenKey(token)\n }\n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AAAA,EAC/C;AACA,SAAO,YAAY;AACrB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { scimJson } from "../../../../lib/scim-response.js";
|
|
2
|
+
import { checkScimRateLimit } from "../../rate-limit.js";
|
|
2
3
|
const metadata = { requireAuth: false };
|
|
3
|
-
|
|
4
|
+
const beforeAuth = checkScimRateLimit;
|
|
5
|
+
async function GET(req) {
|
|
6
|
+
const rateLimitError = await checkScimRateLimit(req);
|
|
7
|
+
if (rateLimitError) return rateLimitError;
|
|
4
8
|
return scimJson({
|
|
5
9
|
schemas: ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
|
|
6
10
|
documentationUri: "https://open-mercato.com/docs/scim",
|
|
@@ -30,12 +34,16 @@ const openApi = {
|
|
|
30
34
|
description: "Returns SCIM 2.0 ServiceProviderConfig. No authentication required \u2014 used by identity providers during connection testing.",
|
|
31
35
|
tags: ["SSO", "SCIM"],
|
|
32
36
|
responses: [{ status: 200, description: "SCIM ServiceProviderConfig" }],
|
|
33
|
-
errors: [
|
|
37
|
+
errors: [
|
|
38
|
+
{ status: 429, description: "SCIM request limit exceeded; retry after Retry-After seconds" },
|
|
39
|
+
{ status: 503, description: "Rate limiter unavailable" }
|
|
40
|
+
]
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
};
|
|
37
44
|
export {
|
|
38
45
|
GET,
|
|
46
|
+
beforeAuth,
|
|
39
47
|
metadata,
|
|
40
48
|
openApi
|
|
41
49
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/sso/api/scim/v2/ServiceProviderConfig/route.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { scimJson } from '../../../../lib/scim-response'\n\nexport const metadata = { requireAuth: false }\n\nexport async function GET() {\n return scimJson({\n schemas: ['urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig'],\n documentationUri: 'https://open-mercato.com/docs/scim',\n patch: { supported: true },\n bulk: { supported: false, maxOperations: 0, maxPayloadSize: 0 },\n filter: { supported: true, maxResults: 200 },\n changePassword: { supported: false },\n sort: { supported: false },\n etag: { supported: false },\n authenticationSchemes: [\n {\n type: 'oauthbearertoken',\n name: 'OAuth Bearer Token',\n description: 'Authentication scheme using the OAuth Bearer Token standard',\n specUri: 'https://www.rfc-editor.org/info/rfc6750',\n primary: true,\n },\n ],\n })\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'SCIM',\n summary: 'SCIM Service Provider Configuration',\n methods: {\n GET: {\n summary: 'Get SCIM service provider configuration',\n description: 'Returns SCIM 2.0 ServiceProviderConfig. No authentication required \u2014 used by identity providers during connection testing.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'SCIM ServiceProviderConfig' }],\n errors: [],\n },\n },\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { scimJson } from '../../../../lib/scim-response'\nimport { checkScimRateLimit } from '../../rate-limit'\n\nexport const metadata = { requireAuth: false }\nexport const beforeAuth = checkScimRateLimit\n\nexport async function GET(req: Request) {\n const rateLimitError = await checkScimRateLimit(req)\n if (rateLimitError) return rateLimitError\n\n return scimJson({\n schemas: ['urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig'],\n documentationUri: 'https://open-mercato.com/docs/scim',\n patch: { supported: true },\n bulk: { supported: false, maxOperations: 0, maxPayloadSize: 0 },\n filter: { supported: true, maxResults: 200 },\n changePassword: { supported: false },\n sort: { supported: false },\n etag: { supported: false },\n authenticationSchemes: [\n {\n type: 'oauthbearertoken',\n name: 'OAuth Bearer Token',\n description: 'Authentication scheme using the OAuth Bearer Token standard',\n specUri: 'https://www.rfc-editor.org/info/rfc6750',\n primary: true,\n },\n ],\n })\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'SCIM',\n summary: 'SCIM Service Provider Configuration',\n methods: {\n GET: {\n summary: 'Get SCIM service provider configuration',\n description: 'Returns SCIM 2.0 ServiceProviderConfig. No authentication required \u2014 used by identity providers during connection testing.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'SCIM ServiceProviderConfig' }],\n errors: [\n { status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },\n { status: 503, description: 'Rate limiter unavailable' },\n ],\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AAE5B,MAAM,WAAW,EAAE,aAAa,MAAM;AACtC,MAAM,aAAa;AAE1B,eAAsB,IAAI,KAAc;AACtC,QAAM,iBAAiB,MAAM,mBAAmB,GAAG;AACnD,MAAI,eAAgB,QAAO;AAE3B,SAAO,SAAS;AAAA,IACd,SAAS,CAAC,6DAA6D;AAAA,IACvE,kBAAkB;AAAA,IAClB,OAAO,EAAE,WAAW,KAAK;AAAA,IACzB,MAAM,EAAE,WAAW,OAAO,eAAe,GAAG,gBAAgB,EAAE;AAAA,IAC9D,QAAQ,EAAE,WAAW,MAAM,YAAY,IAAI;AAAA,IAC3C,gBAAgB,EAAE,WAAW,MAAM;AAAA,IACnC,MAAM,EAAE,WAAW,MAAM;AAAA,IACzB,MAAM,EAAE,WAAW,MAAM;AAAA,IACzB,uBAAuB;AAAA,MACrB;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,QACN,aAAa;AAAA,QACb,SAAS;AAAA,QACT,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,MAAM,UAA2B;AAAA,EACtC,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA,IACP,KAAK;AAAA,MACH,SAAS;AAAA,MACT,aAAa;AAAA,MACb,MAAM,CAAC,OAAO,MAAM;AAAA,MACpB,WAAW,CAAC,EAAE,QAAQ,KAAK,aAAa,6BAA6B,CAAC;AAAA,MACtE,QAAQ;AAAA,QACN,EAAE,QAAQ,KAAK,aAAa,+DAA+D;AAAA,QAC3F,EAAE,QAAQ,KAAK,aAAa,2BAA2B;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,6 +4,7 @@ import { parseScimPatchOperations } from "../../../../../lib/scim-patch.js";
|
|
|
4
4
|
import { scimJson } from "../../../../../lib/scim-response.js";
|
|
5
5
|
import { handleScimApiError } from "../../../../error-handler.js";
|
|
6
6
|
const metadata = { requireAuth: false };
|
|
7
|
+
import { checkScimRateLimit } from "../../../rate-limit.js";
|
|
7
8
|
async function GET(req, ctx) {
|
|
8
9
|
try {
|
|
9
10
|
const { id } = await ctx.params;
|
|
@@ -58,7 +59,9 @@ const openApi = {
|
|
|
58
59
|
responses: [{ status: 200, description: "SCIM User resource" }],
|
|
59
60
|
errors: [
|
|
60
61
|
{ status: 401, description: "Unauthorized" },
|
|
61
|
-
{ status: 404, description: "User not found" }
|
|
62
|
+
{ status: 404, description: "User not found" },
|
|
63
|
+
{ status: 429, description: "SCIM request limit exceeded; retry after Retry-After seconds" },
|
|
64
|
+
{ status: 503, description: "Rate limiter unavailable" }
|
|
62
65
|
]
|
|
63
66
|
},
|
|
64
67
|
PATCH: {
|
|
@@ -69,7 +72,9 @@ const openApi = {
|
|
|
69
72
|
errors: [
|
|
70
73
|
{ status: 400, description: "Invalid PatchOp" },
|
|
71
74
|
{ status: 401, description: "Unauthorized" },
|
|
72
|
-
{ status: 404, description: "User not found" }
|
|
75
|
+
{ status: 404, description: "User not found" },
|
|
76
|
+
{ status: 429, description: "SCIM request limit exceeded; retry after Retry-After seconds" },
|
|
77
|
+
{ status: 503, description: "Rate limiter unavailable" }
|
|
73
78
|
]
|
|
74
79
|
},
|
|
75
80
|
DELETE: {
|
|
@@ -79,7 +84,9 @@ const openApi = {
|
|
|
79
84
|
responses: [{ status: 204, description: "No content" }],
|
|
80
85
|
errors: [
|
|
81
86
|
{ status: 401, description: "Unauthorized" },
|
|
82
|
-
{ status: 404, description: "User not found" }
|
|
87
|
+
{ status: 404, description: "User not found" },
|
|
88
|
+
{ status: 429, description: "SCIM request limit exceeded; retry after Retry-After seconds" },
|
|
89
|
+
{ status: 503, description: "Rate limiter unavailable" }
|
|
83
90
|
]
|
|
84
91
|
}
|
|
85
92
|
}
|
|
@@ -88,6 +95,7 @@ export {
|
|
|
88
95
|
DELETE,
|
|
89
96
|
GET,
|
|
90
97
|
PATCH,
|
|
98
|
+
checkScimRateLimit as beforeAuth,
|
|
91
99
|
metadata,
|
|
92
100
|
openApi
|
|
93
101
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../src/modules/sso/api/scim/v2/Users/%5Bid%5D/route.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveScimContext } from '../../../context'\nimport { ScimService } from '../../../../../services/scimService'\nimport { parseScimPatchOperations } from '../../../../../lib/scim-patch'\nimport { scimJson } from '../../../../../lib/scim-response'\nimport { handleScimApiError } from '../../../../error-handler'\n\nexport const metadata = { requireAuth: false }\n\ntype RouteContext = { params: Promise<{ id: string }> }\n\nexport async function GET(req: Request, ctx: RouteContext) {\n try {\n const { id } = await ctx.params\n const scimCtx = await resolveScimContext(req)\n if (!scimCtx.ok) return scimCtx.response\n\n const baseUrl = new URL(req.url).origin\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const resource = await service.getUser(id, scimCtx.scope, baseUrl)\n\n return scimJson(resource)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\nexport async function PATCH(req: Request, ctx: RouteContext) {\n try {\n const { id } = await ctx.params\n const scimCtx = await resolveScimContext(req)\n if (!scimCtx.ok) return scimCtx.response\n\n const body = await req.json()\n const operations = parseScimPatchOperations(body)\n const baseUrl = new URL(req.url).origin\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const resource = await service.patchUser(id, operations, scimCtx.scope, baseUrl)\n\n return scimJson(resource)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\nexport async function DELETE(req: Request, ctx: RouteContext) {\n try {\n const { id } = await ctx.params\n const scimCtx = await resolveScimContext(req)\n if (!scimCtx.ok) return scimCtx.response\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n await service.deleteUser(id, scimCtx.scope)\n\n return new Response(null, { status: 204 })\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'SCIM',\n summary: 'SCIM User by ID',\n methods: {\n GET: {\n summary: 'Get SCIM user',\n description: 'Returns a single provisioned user by SCIM ID.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'SCIM User resource' }],\n errors: [\n { status: 401, description: 'Unauthorized' },\n { status: 404, description: 'User not found' },\n ],\n },\n PATCH: {\n summary: 'Patch SCIM user',\n description: 'Updates user attributes via SCIM PatchOp. Supports active/inactive toggling.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'Updated SCIM User resource' }],\n errors: [\n { status: 400, description: 'Invalid PatchOp' },\n { status: 401, description: 'Unauthorized' },\n { status: 404, description: 'User not found' },\n ],\n },\n DELETE: {\n summary: 'Delete SCIM user',\n description: 'Deactivates the user and revokes sessions.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 204, description: 'No content' }],\n errors: [\n { status: 401, description: 'Unauthorized' },\n { status: 404, description: 'User not found' },\n ],\n },\n },\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAEnC,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AAE5B,MAAM,WAAW,EAAE,aAAa,MAAM;
|
|
4
|
+
"sourcesContent": ["import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveScimContext } from '../../../context'\nimport { ScimService } from '../../../../../services/scimService'\nimport { parseScimPatchOperations } from '../../../../../lib/scim-patch'\nimport { scimJson } from '../../../../../lib/scim-response'\nimport { handleScimApiError } from '../../../../error-handler'\n\nexport const metadata = { requireAuth: false }\nexport { checkScimRateLimit as beforeAuth } from '../../../rate-limit'\n\ntype RouteContext = { params: Promise<{ id: string }> }\n\nexport async function GET(req: Request, ctx: RouteContext) {\n try {\n const { id } = await ctx.params\n const scimCtx = await resolveScimContext(req)\n if (!scimCtx.ok) return scimCtx.response\n\n const baseUrl = new URL(req.url).origin\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const resource = await service.getUser(id, scimCtx.scope, baseUrl)\n\n return scimJson(resource)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\nexport async function PATCH(req: Request, ctx: RouteContext) {\n try {\n const { id } = await ctx.params\n const scimCtx = await resolveScimContext(req)\n if (!scimCtx.ok) return scimCtx.response\n\n const body = await req.json()\n const operations = parseScimPatchOperations(body)\n const baseUrl = new URL(req.url).origin\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const resource = await service.patchUser(id, operations, scimCtx.scope, baseUrl)\n\n return scimJson(resource)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\nexport async function DELETE(req: Request, ctx: RouteContext) {\n try {\n const { id } = await ctx.params\n const scimCtx = await resolveScimContext(req)\n if (!scimCtx.ok) return scimCtx.response\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n await service.deleteUser(id, scimCtx.scope)\n\n return new Response(null, { status: 204 })\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'SCIM',\n summary: 'SCIM User by ID',\n methods: {\n GET: {\n summary: 'Get SCIM user',\n description: 'Returns a single provisioned user by SCIM ID.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'SCIM User resource' }],\n errors: [\n { status: 401, description: 'Unauthorized' },\n { status: 404, description: 'User not found' },\n { status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },\n { status: 503, description: 'Rate limiter unavailable' },\n ],\n },\n PATCH: {\n summary: 'Patch SCIM user',\n description: 'Updates user attributes via SCIM PatchOp. Supports active/inactive toggling.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'Updated SCIM User resource' }],\n errors: [\n { status: 400, description: 'Invalid PatchOp' },\n { status: 401, description: 'Unauthorized' },\n { status: 404, description: 'User not found' },\n { status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },\n { status: 503, description: 'Rate limiter unavailable' },\n ],\n },\n DELETE: {\n summary: 'Delete SCIM user',\n description: 'Deactivates the user and revokes sessions.',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 204, description: 'No content' }],\n errors: [\n { status: 401, description: 'Unauthorized' },\n { status: 404, description: 'User not found' },\n { status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },\n { status: 503, description: 'Rate limiter unavailable' },\n ],\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAEnC,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AAE5B,MAAM,WAAW,EAAE,aAAa,MAAM;AAC7C,SAA+B,0BAAkB;AAIjD,eAAsB,IAAI,KAAc,KAAmB;AACzD,MAAI;AACF,UAAM,EAAE,GAAG,IAAI,MAAM,IAAI;AACzB,UAAM,UAAU,MAAM,mBAAmB,GAAG;AAC5C,QAAI,CAAC,QAAQ,GAAI,QAAO,QAAQ;AAEhC,UAAM,UAAU,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ACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,6 +4,7 @@ import { handleScimApiError } from "../../../error-handler.js";
|
|
|
4
4
|
import { scimUserPayloadSchema } from "../../../../data/validators.js";
|
|
5
5
|
import { buildScimError, scimJson as scimJsonResponse } from "../../../../lib/scim-response.js";
|
|
6
6
|
const metadata = { requireAuth: false };
|
|
7
|
+
import { checkScimRateLimit } from "../../rate-limit.js";
|
|
7
8
|
async function POST(req) {
|
|
8
9
|
try {
|
|
9
10
|
const ctx = await resolveScimContext(req);
|
|
@@ -62,7 +63,9 @@ const openApi = {
|
|
|
62
63
|
{ status: 400, description: "Invalid payload" },
|
|
63
64
|
{ status: 401, description: "Unauthorized" },
|
|
64
65
|
{ status: 403, description: "SSO config inactive" },
|
|
65
|
-
{ status: 409, description: "Conflict \u2014 user already linked" }
|
|
66
|
+
{ status: 409, description: "Conflict \u2014 user already linked" },
|
|
67
|
+
{ status: 429, description: "SCIM request limit exceeded; retry after Retry-After seconds" },
|
|
68
|
+
{ status: 503, description: "Rate limiter unavailable" }
|
|
66
69
|
]
|
|
67
70
|
},
|
|
68
71
|
GET: {
|
|
@@ -72,7 +75,9 @@ const openApi = {
|
|
|
72
75
|
responses: [{ status: 200, description: "SCIM ListResponse" }],
|
|
73
76
|
errors: [
|
|
74
77
|
{ status: 401, description: "Unauthorized" },
|
|
75
|
-
{ status: 403, description: "SSO config inactive" }
|
|
78
|
+
{ status: 403, description: "SSO config inactive" },
|
|
79
|
+
{ status: 429, description: "SCIM request limit exceeded; retry after Retry-After seconds" },
|
|
80
|
+
{ status: 503, description: "Rate limiter unavailable" }
|
|
76
81
|
]
|
|
77
82
|
}
|
|
78
83
|
}
|
|
@@ -80,6 +85,7 @@ const openApi = {
|
|
|
80
85
|
export {
|
|
81
86
|
GET,
|
|
82
87
|
POST,
|
|
88
|
+
checkScimRateLimit as beforeAuth,
|
|
83
89
|
metadata,
|
|
84
90
|
openApi
|
|
85
91
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/sso/api/scim/v2/Users/route.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveScimContext } from '../../context'\nimport { ScimService } from '../../../../services/scimService'\nimport { handleScimApiError } from '../../../error-handler'\nimport { scimUserPayloadSchema } from '../../../../data/validators'\nimport { buildScimError, scimJson as scimJsonResponse } from '../../../../lib/scim-response'\n\nexport const metadata = { requireAuth: false }\n\nexport async function POST(req: Request) {\n try {\n const ctx = await resolveScimContext(req)\n if (!ctx.ok) return ctx.response\n\n const body = await req.json()\n const parsed = scimUserPayloadSchema.safeParse(body)\n if (!parsed.success) {\n return scimJsonResponse(\n buildScimError(400, parsed.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join('; '), 'invalidValue'),\n 400,\n )\n }\n\n const baseUrl = new URL(req.url).origin\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const { resource, status } = await service.createUser(parsed.data, ctx.scope, baseUrl)\n\n const headers: Record<string, string> = {}\n if (status === 201) {\n headers.Location = resource.meta.location\n }\n\n return scimJsonResponse(resource, status)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\nexport async function GET(req: Request) {\n try {\n const ctx = await resolveScimContext(req)\n if (!ctx.ok) return ctx.response\n\n const url = new URL(req.url)\n const filter = url.searchParams.get('filter')\n const startIndex = Math.max(1, parseInt(url.searchParams.get('startIndex') ?? '1', 10) || 1)\n const count = Math.min(200, Math.max(1, parseInt(url.searchParams.get('count') ?? '100', 10) || 100))\n const baseUrl = url.origin\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const result = await service.listUsers(filter, startIndex, count, ctx.scope, baseUrl)\n\n return scimJsonResponse(result)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'SCIM',\n summary: 'SCIM Users',\n methods: {\n POST: {\n summary: 'Create SCIM user',\n description: 'Provisions a new user via SCIM 2.0. Supports idempotency via externalId.',\n tags: ['SSO', 'SCIM'],\n responses: [\n { status: 201, description: 'User created' },\n { status: 200, description: 'User already exists (idempotent)' },\n ],\n errors: [\n { status: 400, description: 'Invalid payload' },\n { status: 401, description: 'Unauthorized' },\n { status: 403, description: 'SSO config inactive' },\n { status: 409, description: 'Conflict \u2014 user already linked' },\n ],\n },\n GET: {\n summary: 'List SCIM users',\n description: 'Lists provisioned users with optional SCIM filter (eq operator).',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'SCIM ListResponse' }],\n errors: [\n { status: 401, description: 'Unauthorized' },\n { status: 403, description: 'SSO config inactive' },\n ],\n },\n },\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,gBAAgB,YAAY,wBAAwB;AAEtD,MAAM,WAAW,EAAE,aAAa,MAAM;
|
|
4
|
+
"sourcesContent": ["import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveScimContext } from '../../context'\nimport { ScimService } from '../../../../services/scimService'\nimport { handleScimApiError } from '../../../error-handler'\nimport { scimUserPayloadSchema } from '../../../../data/validators'\nimport { buildScimError, scimJson as scimJsonResponse } from '../../../../lib/scim-response'\n\nexport const metadata = { requireAuth: false }\nexport { checkScimRateLimit as beforeAuth } from '../../rate-limit'\n\nexport async function POST(req: Request) {\n try {\n const ctx = await resolveScimContext(req)\n if (!ctx.ok) return ctx.response\n\n const body = await req.json()\n const parsed = scimUserPayloadSchema.safeParse(body)\n if (!parsed.success) {\n return scimJsonResponse(\n buildScimError(400, parsed.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join('; '), 'invalidValue'),\n 400,\n )\n }\n\n const baseUrl = new URL(req.url).origin\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const { resource, status } = await service.createUser(parsed.data, ctx.scope, baseUrl)\n\n const headers: Record<string, string> = {}\n if (status === 201) {\n headers.Location = resource.meta.location\n }\n\n return scimJsonResponse(resource, status)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\nexport async function GET(req: Request) {\n try {\n const ctx = await resolveScimContext(req)\n if (!ctx.ok) return ctx.response\n\n const url = new URL(req.url)\n const filter = url.searchParams.get('filter')\n const startIndex = Math.max(1, parseInt(url.searchParams.get('startIndex') ?? '1', 10) || 1)\n const count = Math.min(200, Math.max(1, parseInt(url.searchParams.get('count') ?? '100', 10) || 100))\n const baseUrl = url.origin\n\n const container = await createRequestContainer()\n const service = container.resolve<ScimService>('scimService')\n const result = await service.listUsers(filter, startIndex, count, ctx.scope, baseUrl)\n\n return scimJsonResponse(result)\n } catch (err) {\n return handleScimApiError(err, 'SCIM Users API')\n }\n}\n\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'SCIM',\n summary: 'SCIM Users',\n methods: {\n POST: {\n summary: 'Create SCIM user',\n description: 'Provisions a new user via SCIM 2.0. Supports idempotency via externalId.',\n tags: ['SSO', 'SCIM'],\n responses: [\n { status: 201, description: 'User created' },\n { status: 200, description: 'User already exists (idempotent)' },\n ],\n errors: [\n { status: 400, description: 'Invalid payload' },\n { status: 401, description: 'Unauthorized' },\n { status: 403, description: 'SSO config inactive' },\n { status: 409, description: 'Conflict \u2014 user already linked' },\n { status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },\n { status: 503, description: 'Rate limiter unavailable' },\n ],\n },\n GET: {\n summary: 'List SCIM users',\n description: 'Lists provisioned users with optional SCIM filter (eq operator).',\n tags: ['SSO', 'SCIM'],\n responses: [{ status: 200, description: 'SCIM ListResponse' }],\n errors: [\n { status: 401, description: 'Unauthorized' },\n { status: 403, description: 'SSO config inactive' },\n { status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },\n { status: 503, description: 'Rate limiter unavailable' },\n ],\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,gBAAgB,YAAY,wBAAwB;AAEtD,MAAM,WAAW,EAAE,aAAa,MAAM;AAC7C,SAA+B,0BAAkB;AAEjD,eAAsB,KAAK,KAAc;AACvC,MAAI;AACF,UAAM,MAAM,MAAM,mBAAmB,GAAG;AACxC,QAAI,CAAC,IAAI,GAAI,QAAO,IAAI;AAExB,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,SAAS,sBAAsB,UAAU,IAAI;AACnD,QAAI,CAAC,OAAO,SAAS;AACnB,aAAO;AAAA,QACL,eAAe,KAAK,OAAO,MAAM,OAAO,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,IAAI,GAAG,cAAc;AAAA,QAClH;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAU,IAAI,IAAI,IAAI,GAAG,EAAE;AAEjC,UAAM,YAAY,MAAM,uBAAuB;AAC/C,UAAM,UAAU,UAAU,QAAqB,aAAa;AAC5D,UAAM,EAAE,UAAU,OAAO,IAAI,MAAM,QAAQ,WAAW,OAAO,MAAM,IAAI,OAAO,OAAO;AAErF,UAAM,UAAkC,CAAC;AACzC,QAAI,WAAW,KAAK;AAClB,cAAQ,WAAW,SAAS,KAAK;AAAA,IACnC;AAEA,WAAO,iBAAiB,UAAU,MAAM;AAAA,EAC1C,SAAS,KAAK;AACZ,WAAO,mBAAmB,KAAK,gBAAgB;AAAA,EACjD;AACF;AAEA,eAAsB,IAAI,KAAc;AACtC,MAAI;AACF,UAAM,MAAM,MAAM,mBA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A,IACA,KAAK;AAAA,MACH,SAAS;AAAA,MACT,aAAa;AAAA,MACb,MAAM,CAAC,OAAO,MAAM;AAAA,MACpB,WAAW,CAAC,EAAE,QAAQ,KAAK,aAAa,oBAAoB,CAAC;AAAA,MAC7D,QAAQ;AAAA,QACN,EAAE,QAAQ,KAAK,aAAa,eAAe;AAAA,QAC3C,EAAE,QAAQ,KAAK,aAAa,sBAAsB;AAAA,QAClD,EAAE,QAAQ,KAAK,aAAa,+DAA+D;AAAA,QAC3F,EAAE,QAAQ,KAAK,aAAa,2BAA2B;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -161,6 +161,10 @@ __decorateClass([
|
|
|
161
161
|
__decorateClass([
|
|
162
162
|
Property({ name: "token_hash", type: "text" })
|
|
163
163
|
], ScimToken.prototype, "tokenHash", 2);
|
|
164
|
+
__decorateClass([
|
|
165
|
+
Property({ name: "token_lookup_hash", type: "text", nullable: true }),
|
|
166
|
+
Index({ name: "scim_tokens_token_lookup_hash_idx" })
|
|
167
|
+
], ScimToken.prototype, "tokenLookupHash", 2);
|
|
164
168
|
__decorateClass([
|
|
165
169
|
Property({ name: "token_prefix", type: "text" })
|
|
166
170
|
], ScimToken.prototype, "tokenPrefix", 2);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sso/data/entities.ts"],
|
|
4
|
-
"sourcesContent": ["import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n@Entity({ tableName: 'sso_configs' })\n// Unique index on organization_id (partial: WHERE deleted_at IS NULL) \u2014 managed by migration\nexport class SsoConfig {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ type: 'text', nullable: true })\n name?: string | null\n\n @Property({ type: 'text' })\n protocol!: string\n\n @Property({ type: 'text', nullable: true })\n issuer?: string | null\n\n @Property({ name: 'client_id', type: 'text', nullable: true })\n clientId?: string | null\n\n @Property({ name: 'client_secret_enc', type: 'text', nullable: true })\n clientSecretEnc?: string | null\n\n @Property({ name: 'allowed_domains', type: 'jsonb', default: '[]' })\n allowedDomains: string[] = []\n\n @Property({ name: 'jit_enabled', type: 'boolean', default: true })\n jitEnabled: boolean = true\n\n @Property({ name: 'auto_link_by_email', type: 'boolean', default: true })\n autoLinkByEmail: boolean = true\n\n @Property({ name: 'is_active', type: 'boolean', default: false })\n isActive: boolean = false\n\n @Property({ name: 'sso_required', type: 'boolean', default: false })\n ssoRequired: boolean = false\n\n @Property({ name: 'app_role_mappings', type: 'jsonb', default: '{}' })\n appRoleMappings: Record<string, string> = {}\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'sso_identities' })\n// Unique indexes (partial: WHERE deleted_at IS NULL) \u2014 managed by migration\nexport class SsoIdentity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n @Index({ name: 'sso_identities_config_id_idx' })\n ssoConfigId!: string\n\n @Property({ name: 'user_id', type: 'uuid' })\n @Index({ name: 'sso_identities_user_id_idx' })\n userId!: string\n\n @Property({ name: 'idp_subject', type: 'text' })\n idpSubject!: string\n\n @Property({ name: 'idp_email', type: 'text' })\n idpEmail!: string\n\n @Property({ name: 'idp_name', type: 'text', nullable: true })\n idpName?: string | null\n\n @Property({ name: 'idp_groups', type: 'jsonb', default: '[]' })\n idpGroups: string[] = []\n\n @Property({ name: 'external_id', type: 'text', nullable: true })\n externalId?: string | null\n\n @Property({ name: 'provisioning_method', type: 'text' })\n provisioningMethod!: string\n\n @Property({ name: 'first_login_at', type: Date, nullable: true })\n firstLoginAt?: Date | null\n\n @Property({ name: 'last_login_at', type: Date, nullable: true })\n lastLoginAt?: Date | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'scim_tokens' })\n@Index({ name: 'scim_tokens_token_prefix_idx', properties: ['tokenPrefix'] })\nexport class ScimToken {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n @Index({ name: 'scim_tokens_sso_config_id_idx' })\n ssoConfigId!: string\n\n @Property({ type: 'text' })\n name!: string\n\n @Property({ name: 'token_hash', type: 'text' })\n tokenHash!: string\n\n @Property({ name: 'token_prefix', type: 'text' })\n tokenPrefix!: string\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_by', type: 'uuid', nullable: true })\n createdBy?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'sso_user_deactivations' })\n@Unique({ properties: ['userId', 'ssoConfigId'], name: 'sso_user_deactivations_user_config_unique' })\nexport class SsoUserDeactivation {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'user_id', type: 'uuid' })\n @Index({ name: 'sso_user_deactivations_user_id_idx' })\n userId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n ssoConfigId!: string\n\n @Property({ name: 'deactivated_at', type: Date })\n deactivatedAt: Date = new Date()\n\n @Property({ name: 'reactivated_at', type: Date, nullable: true })\n reactivatedAt?: Date | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n\n@Entity({ tableName: 'scim_provisioning_log' })\n@Index({ name: 'scim_provisioning_log_config_created_idx', properties: ['ssoConfigId', 'createdAt'] })\nexport class ScimProvisioningLog {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n ssoConfigId!: string\n\n @Property({ type: 'text' })\n operation!: string\n\n @Property({ name: 'resource_type', type: 'text' })\n resourceType!: string\n\n @Property({ name: 'resource_id', type: 'uuid', nullable: true })\n resourceId?: string | null\n\n @Property({ name: 'scim_external_id', type: 'text', nullable: true })\n scimExternalId?: string | null\n\n @Property({ name: 'response_status', type: 'integer' })\n responseStatus!: number\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n\n@Entity({ tableName: 'sso_role_grants' })\n@Unique({ properties: ['userId', 'roleId', 'ssoConfigId'], name: 'sso_role_grants_user_role_config_unique' })\nexport class SsoRoleGrant {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'user_id', type: 'uuid' })\n @Index({ name: 'sso_role_grants_user_id_idx' })\n userId!: string\n\n @Property({ name: 'role_id', type: 'uuid' })\n roleId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n ssoConfigId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;AAAA,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AAIrD,IAAM,YAAN,MAAgB;AAAA,EAAhB;AA0BL,0BAA2B,CAAC;AAG5B,sBAAsB;AAGtB,2BAA2B;AAG3B,oBAAoB;AAGpB,uBAAuB;AAGvB,2BAA0C,CAAC;AAG3C,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AAjDE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GADlD,UAEX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAJlD,UAKX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAPxC,UAQX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAV/B,UAWX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAbf,UAcX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAhB/B,UAiBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,KAAK,CAAC;AAA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S,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GA1C7D,YA2CX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,GAAG,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GA7CzF,YA8CX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,KAAK,CAAC;AAAA,GAhDjD,YAiDX;AAjDW,cAAN;AAAA,EAFN,OAAO,EAAE,WAAW,iBAAiB,CAAC;AAAA,GAE1B;AAsDN,IAAM,YAAN,MAAgB;AAAA,EAAhB;
|
|
4
|
+
"sourcesContent": ["import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n@Entity({ tableName: 'sso_configs' })\n// Unique index on organization_id (partial: WHERE deleted_at IS NULL) \u2014 managed by migration\nexport class SsoConfig {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ type: 'text', nullable: true })\n name?: string | null\n\n @Property({ type: 'text' })\n protocol!: string\n\n @Property({ type: 'text', nullable: true })\n issuer?: string | null\n\n @Property({ name: 'client_id', type: 'text', nullable: true })\n clientId?: string | null\n\n @Property({ name: 'client_secret_enc', type: 'text', nullable: true })\n clientSecretEnc?: string | null\n\n @Property({ name: 'allowed_domains', type: 'jsonb', default: '[]' })\n allowedDomains: string[] = []\n\n @Property({ name: 'jit_enabled', type: 'boolean', default: true })\n jitEnabled: boolean = true\n\n @Property({ name: 'auto_link_by_email', type: 'boolean', default: true })\n autoLinkByEmail: boolean = true\n\n @Property({ name: 'is_active', type: 'boolean', default: false })\n isActive: boolean = false\n\n @Property({ name: 'sso_required', type: 'boolean', default: false })\n ssoRequired: boolean = false\n\n @Property({ name: 'app_role_mappings', type: 'jsonb', default: '{}' })\n appRoleMappings: Record<string, string> = {}\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'sso_identities' })\n// Unique indexes (partial: WHERE deleted_at IS NULL) \u2014 managed by migration\nexport class SsoIdentity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n @Index({ name: 'sso_identities_config_id_idx' })\n ssoConfigId!: string\n\n @Property({ name: 'user_id', type: 'uuid' })\n @Index({ name: 'sso_identities_user_id_idx' })\n userId!: string\n\n @Property({ name: 'idp_subject', type: 'text' })\n idpSubject!: string\n\n @Property({ name: 'idp_email', type: 'text' })\n idpEmail!: string\n\n @Property({ name: 'idp_name', type: 'text', nullable: true })\n idpName?: string | null\n\n @Property({ name: 'idp_groups', type: 'jsonb', default: '[]' })\n idpGroups: string[] = []\n\n @Property({ name: 'external_id', type: 'text', nullable: true })\n externalId?: string | null\n\n @Property({ name: 'provisioning_method', type: 'text' })\n provisioningMethod!: string\n\n @Property({ name: 'first_login_at', type: Date, nullable: true })\n firstLoginAt?: Date | null\n\n @Property({ name: 'last_login_at', type: Date, nullable: true })\n lastLoginAt?: Date | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'scim_tokens' })\n@Index({ name: 'scim_tokens_token_prefix_idx', properties: ['tokenPrefix'] })\nexport class ScimToken {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n @Index({ name: 'scim_tokens_sso_config_id_idx' })\n ssoConfigId!: string\n\n @Property({ type: 'text' })\n name!: string\n\n @Property({ name: 'token_hash', type: 'text' })\n tokenHash!: string\n\n @Property({ name: 'token_lookup_hash', type: 'text', nullable: true })\n @Index({ name: 'scim_tokens_token_lookup_hash_idx' })\n tokenLookupHash?: string | null\n\n @Property({ name: 'token_prefix', type: 'text' })\n tokenPrefix!: string\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'created_by', type: 'uuid', nullable: true })\n createdBy?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onCreate: () => new Date(), onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'sso_user_deactivations' })\n@Unique({ properties: ['userId', 'ssoConfigId'], name: 'sso_user_deactivations_user_config_unique' })\nexport class SsoUserDeactivation {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'user_id', type: 'uuid' })\n @Index({ name: 'sso_user_deactivations_user_id_idx' })\n userId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n ssoConfigId!: string\n\n @Property({ name: 'deactivated_at', type: Date })\n deactivatedAt: Date = new Date()\n\n @Property({ name: 'reactivated_at', type: Date, nullable: true })\n reactivatedAt?: Date | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n\n@Entity({ tableName: 'scim_provisioning_log' })\n@Index({ name: 'scim_provisioning_log_config_created_idx', properties: ['ssoConfigId', 'createdAt'] })\nexport class ScimProvisioningLog {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n ssoConfigId!: string\n\n @Property({ type: 'text' })\n operation!: string\n\n @Property({ name: 'resource_type', type: 'text' })\n resourceType!: string\n\n @Property({ name: 'resource_id', type: 'uuid', nullable: true })\n resourceId?: string | null\n\n @Property({ name: 'scim_external_id', type: 'text', nullable: true })\n scimExternalId?: string | null\n\n @Property({ name: 'response_status', type: 'integer' })\n responseStatus!: number\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n\n@Entity({ tableName: 'sso_role_grants' })\n@Unique({ properties: ['userId', 'roleId', 'ssoConfigId'], name: 'sso_role_grants_user_role_config_unique' })\nexport class SsoRoleGrant {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'user_id', type: 'uuid' })\n @Index({ name: 'sso_role_grants_user_id_idx' })\n userId!: string\n\n @Property({ name: 'role_id', type: 'uuid' })\n roleId!: string\n\n @Property({ name: 'sso_config_id', type: 'uuid' })\n ssoConfigId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}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qCN,IAAM,eAAN,MAAmB;AAAA,EAAnB;AAqBL,qBAAkB,oBAAI,KAAK;AAAA;AAC7B;AApBE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GADlD,aAEX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAJlD,aAKX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAPxC,aAQX;AAIA;AAAA,EAFC,SAAS,EAAE,MAAM,WAAW,MAAM,OAAO,CAAC;AAAA,EAC1C,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAAA,GAXnC,aAYX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,WAAW,MAAM,OAAO,CAAC;AAAA,GAdhC,aAeX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,iBAAiB,MAAM,OAAO,CAAC;AAAA,GAjBtC,aAkBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GApB7D,aAqBX;AArBW,eAAN;AAAA,EAFN,OAAO,EAAE,WAAW,kBAAkB,CAAC;AAAA,EACvC,OAAO,EAAE,YAAY,CAAC,UAAU,UAAU,aAAa,GAAG,MAAM,0CAA0C,CAAC;AAAA,GAC/F;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { runWithCacheTenant } from "@open-mercato/cache";
|
|
3
|
+
const SCIM_ADMISSION_TTL_MS = 3e4;
|
|
4
|
+
function scimTokenLookupHash(rawToken) {
|
|
5
|
+
return createHash("sha256").update(rawToken).digest("hex");
|
|
6
|
+
}
|
|
7
|
+
function scimAdmissionCacheKey(rawToken) {
|
|
8
|
+
return `sso:scim-admission:${scimTokenLookupHash(rawToken)}`;
|
|
9
|
+
}
|
|
10
|
+
function scimAdmissionTokenKey(token) {
|
|
11
|
+
return `token:${token.tenantId ?? "global"}:${token.organizationId}:${token.id}`;
|
|
12
|
+
}
|
|
13
|
+
function scimAdmissionTokenTag(tokenId) {
|
|
14
|
+
return `sso:scim-admission:token:${tokenId}`;
|
|
15
|
+
}
|
|
16
|
+
async function readScimAdmissionKey(cache, rawToken) {
|
|
17
|
+
const cached = await runWithCacheTenant(null, () => cache.get(scimAdmissionCacheKey(rawToken)));
|
|
18
|
+
return typeof cached === "string" && cached.startsWith("token:") ? cached : null;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
SCIM_ADMISSION_TTL_MS,
|
|
22
|
+
readScimAdmissionKey,
|
|
23
|
+
scimAdmissionCacheKey,
|
|
24
|
+
scimAdmissionTokenKey,
|
|
25
|
+
scimAdmissionTokenTag,
|
|
26
|
+
scimTokenLookupHash
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=scim-admission-cache.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/sso/lib/scim-admission-cache.ts"],
|
|
4
|
+
"sourcesContent": ["import { createHash } from 'node:crypto'\nimport type { CacheStrategy } from '@open-mercato/cache'\nimport { runWithCacheTenant } from '@open-mercato/cache'\n\nexport const SCIM_ADMISSION_TTL_MS = 30_000\n\nexport function scimTokenLookupHash(rawToken: string): string {\n return createHash('sha256').update(rawToken).digest('hex')\n}\n\nexport function scimAdmissionCacheKey(rawToken: string): string {\n return `sso:scim-admission:${scimTokenLookupHash(rawToken)}`\n}\n\nexport function scimAdmissionTokenKey(token: { id: string; tenantId?: string | null; organizationId: string }): string {\n return `token:${token.tenantId ?? 'global'}:${token.organizationId}:${token.id}`\n}\n\nexport function scimAdmissionTokenTag(tokenId: string): string {\n return `sso:scim-admission:token:${tokenId}`\n}\n\nexport async function readScimAdmissionKey(cache: CacheStrategy, rawToken: string): Promise<string | null> {\n const cached = await runWithCacheTenant(null, () => cache.get(scimAdmissionCacheKey(rawToken)))\n return typeof cached === 'string' && cached.startsWith('token:') ? cached : null\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAE3B,SAAS,0BAA0B;AAE5B,MAAM,wBAAwB;AAE9B,SAAS,oBAAoB,UAA0B;AAC5D,SAAO,WAAW,QAAQ,EAAE,OAAO,QAAQ,EAAE,OAAO,KAAK;AAC3D;AAEO,SAAS,sBAAsB,UAA0B;AAC9D,SAAO,sBAAsB,oBAAoB,QAAQ,CAAC;AAC5D;AAEO,SAAS,sBAAsB,OAAiF;AACrH,SAAO,SAAS,MAAM,YAAY,QAAQ,IAAI,MAAM,cAAc,IAAI,MAAM,EAAE;AAChF;AAEO,SAAS,sBAAsB,SAAyB;AAC7D,SAAO,4BAA4B,OAAO;AAC5C;AAEA,eAAsB,qBAAqB,OAAsB,UAA0C;AACzG,QAAM,SAAS,MAAM,mBAAmB,MAAM,MAAM,MAAM,IAAI,sBAAsB,QAAQ,CAAC,CAAC;AAC9F,SAAO,OAAO,WAAW,YAAY,OAAO,WAAW,QAAQ,IAAI,SAAS;AAC9E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Migration } from "@mikro-orm/migrations";
|
|
2
|
+
class Migration20261029160000_scim_token_lookup_hash extends Migration {
|
|
3
|
+
async up() {
|
|
4
|
+
this.addSql('alter table "scim_tokens" add column "token_lookup_hash" text null;');
|
|
5
|
+
this.addSql('create index "scim_tokens_token_lookup_hash_idx" on "scim_tokens" ("token_lookup_hash");');
|
|
6
|
+
}
|
|
7
|
+
async down() {
|
|
8
|
+
this.addSql('drop index if exists "scim_tokens_token_lookup_hash_idx";');
|
|
9
|
+
this.addSql('alter table "scim_tokens" drop column "token_lookup_hash";');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
Migration20261029160000_scim_token_lookup_hash
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=Migration20261029160000_scim_token_lookup_hash.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/sso/migrations/Migration20261029160000_scim_token_lookup_hash.ts"],
|
|
4
|
+
"sourcesContent": ["import { Migration } from '@mikro-orm/migrations'\n\nexport class Migration20261029160000_scim_token_lookup_hash extends Migration {\n override async up(): Promise<void> {\n this.addSql('alter table \"scim_tokens\" add column \"token_lookup_hash\" text null;')\n this.addSql('create index \"scim_tokens_token_lookup_hash_idx\" on \"scim_tokens\" (\"token_lookup_hash\");')\n }\n\n override async down(): Promise<void> {\n this.addSql('drop index if exists \"scim_tokens_token_lookup_hash_idx\";')\n this.addSql('alter table \"scim_tokens\" drop column \"token_lookup_hash\";')\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAEnB,MAAM,uDAAuD,UAAU;AAAA,EAC5E,MAAe,KAAoB;AACjC,SAAK,OAAO,qEAAqE;AACjF,SAAK,OAAO,0FAA0F;AAAA,EACxG;AAAA,EAEA,MAAe,OAAsB;AACnC,SAAK,OAAO,2DAA2D;AACvE,SAAK,OAAO,4DAA4D;AAAA,EAC1E;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { runWithCacheTenant } from "@open-mercato/cache";
|
|
3
|
+
import { readRateLimitConfig } from "@open-mercato/shared/lib/ratelimit/config";
|
|
4
|
+
import { getTelemetryRuntime } from "@open-mercato/shared/lib/telemetry/runtime";
|
|
5
|
+
import { SCIM_ADMISSION_TTL_MS, scimAdmissionCacheKey, scimAdmissionTokenTag, scimAdmissionTokenKey, scimTokenLookupHash } from "../lib/scim-admission-cache.js";
|
|
2
6
|
import { hash, compare } from "bcryptjs";
|
|
3
7
|
import { ScimToken, SsoConfig } from "../data/entities.js";
|
|
4
8
|
const BCRYPT_COST = 10;
|
|
5
9
|
const TOKEN_PREFIX = "omscim_";
|
|
6
10
|
class ScimTokenService {
|
|
7
|
-
constructor(em) {
|
|
11
|
+
constructor(em, cache) {
|
|
8
12
|
this.em = em;
|
|
13
|
+
this.cache = cache;
|
|
9
14
|
}
|
|
10
15
|
async generateToken(ssoConfigId, name, scope) {
|
|
11
16
|
const where = { id: ssoConfigId, deletedAt: null };
|
|
@@ -21,18 +26,28 @@ class ScimTokenService {
|
|
|
21
26
|
const raw = TOKEN_PREFIX + randomBytes(32).toString("hex");
|
|
22
27
|
const tokenHash = await hash(raw, BCRYPT_COST);
|
|
23
28
|
const tokenPrefix = raw.slice(0, 12);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
try {
|
|
30
|
+
const token = this.em.create(ScimToken, {
|
|
31
|
+
ssoConfigId,
|
|
32
|
+
name,
|
|
33
|
+
tokenHash,
|
|
34
|
+
tokenLookupHash: scimTokenLookupHash(raw),
|
|
35
|
+
tokenPrefix,
|
|
36
|
+
isActive: true,
|
|
37
|
+
createdBy: null,
|
|
38
|
+
tenantId: config.tenantId ?? null,
|
|
39
|
+
organizationId: config.organizationId
|
|
40
|
+
});
|
|
41
|
+
await this.em.persist(token).flush();
|
|
42
|
+
return { id: token.id, token: raw, prefix: tokenPrefix, name };
|
|
43
|
+
} catch {
|
|
44
|
+
const error = new Error("[internal] SCIM token persistence unavailable");
|
|
45
|
+
try {
|
|
46
|
+
getTelemetryRuntime()?.reportError(error, { module: "sso", code: "sso.scim_token_persistence_unavailable" });
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
36
51
|
}
|
|
37
52
|
async verifyToken(rawToken) {
|
|
38
53
|
const prefix = rawToken.slice(0, 12);
|
|
@@ -45,8 +60,44 @@ class ScimTokenService {
|
|
|
45
60
|
return null;
|
|
46
61
|
}
|
|
47
62
|
for (const candidate of candidates) {
|
|
48
|
-
const
|
|
63
|
+
const tokenHash = candidate.tokenHash;
|
|
64
|
+
const isValid = await compare(rawToken, tokenHash);
|
|
49
65
|
if (isValid) {
|
|
66
|
+
if (candidate.tokenLookupHash == null) {
|
|
67
|
+
const tokenLookupHash = scimTokenLookupHash(rawToken);
|
|
68
|
+
const updated = await this.em.nativeUpdate(ScimToken, {
|
|
69
|
+
id: candidate.id,
|
|
70
|
+
tenantId: candidate.tenantId ?? null,
|
|
71
|
+
organizationId: candidate.organizationId,
|
|
72
|
+
ssoConfigId: candidate.ssoConfigId,
|
|
73
|
+
tokenHash,
|
|
74
|
+
isActive: true,
|
|
75
|
+
$or: [{ tokenLookupHash: null }, { tokenLookupHash }]
|
|
76
|
+
}, { tokenLookupHash }).catch(() => {
|
|
77
|
+
const error = new ScimTokenError("[internal] SCIM token enrollment unavailable", 503);
|
|
78
|
+
try {
|
|
79
|
+
getTelemetryRuntime()?.reportError(error, { module: "sso", code: "sso.scim_enrollment_unavailable" });
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
});
|
|
84
|
+
if (updated === 0) return null;
|
|
85
|
+
}
|
|
86
|
+
const cache = this.cache;
|
|
87
|
+
if (cache && readRateLimitConfig().enabled) {
|
|
88
|
+
try {
|
|
89
|
+
await runWithCacheTenant(null, () => cache.set(
|
|
90
|
+
scimAdmissionCacheKey(rawToken),
|
|
91
|
+
scimAdmissionTokenKey(candidate),
|
|
92
|
+
{ ttl: SCIM_ADMISSION_TTL_MS, tags: [scimAdmissionTokenTag(candidate.id)] }
|
|
93
|
+
));
|
|
94
|
+
} catch (error) {
|
|
95
|
+
try {
|
|
96
|
+
getTelemetryRuntime()?.reportError(error, { module: "sso", code: "sso.scim_admission_cache_write_failed" });
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
50
101
|
return {
|
|
51
102
|
ssoConfigId: candidate.ssoConfigId,
|
|
52
103
|
organizationId: candidate.organizationId,
|
|
@@ -63,6 +114,17 @@ class ScimTokenService {
|
|
|
63
114
|
if (!token) throw new ScimTokenError("SCIM token not found", 404);
|
|
64
115
|
token.isActive = false;
|
|
65
116
|
await this.em.flush();
|
|
117
|
+
const cache = this.cache;
|
|
118
|
+
if (cache) {
|
|
119
|
+
try {
|
|
120
|
+
await runWithCacheTenant(null, () => cache.deleteByTags([scimAdmissionTokenTag(token.id)]));
|
|
121
|
+
} catch (error) {
|
|
122
|
+
try {
|
|
123
|
+
getTelemetryRuntime()?.reportError(error, { module: "sso", code: "sso.scim_admission_cache_invalidation_failed" });
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
66
128
|
}
|
|
67
129
|
async listTokens(ssoConfigId, scope) {
|
|
68
130
|
const where = { ssoConfigId };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/sso/services/scimTokenService.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomBytes } from 'node:crypto'\nimport type { RequiredEntityData } from '@mikro-orm/core'\nimport { EntityManager } from '@mikro-orm/postgresql'\nimport { hash, compare } from 'bcryptjs'\nimport { ScimToken, SsoConfig } from '../data/entities'\nimport type { SsoAdminScope } from './ssoConfigService'\n\nconst BCRYPT_COST = 10\nconst TOKEN_PREFIX = 'omscim_'\n\nexport interface ScimTokenPublic {\n id: string\n ssoConfigId: string\n name: string\n tokenPrefix: string\n isActive: boolean\n createdBy: string | null\n createdAt: Date\n}\n\nexport interface ScimTokenCreateResult {\n id: string\n token: string\n prefix: string\n name: string\n}\n\nexport class ScimTokenService {\n constructor(private em: EntityManager) {}\n\n async generateToken(\n ssoConfigId: string,\n name: string,\n scope: SsoAdminScope,\n ): Promise<ScimTokenCreateResult> {\n const where: Record<string, unknown> = { id: ssoConfigId, deletedAt: null }\n if (!scope.isSuperAdmin) {\n if (!scope.organizationId) throw new ScimTokenError('Organization context is required', 403)\n where.organizationId = scope.organizationId\n }\n const config = await this.em.findOne(SsoConfig, where)\n if (!config) throw new ScimTokenError('SSO configuration not found', 404)\n if (config.jitEnabled) {\n throw new ScimTokenError('Cannot create SCIM tokens while JIT provisioning is enabled. Disable JIT first.', 409)\n }\n\n const raw = TOKEN_PREFIX + randomBytes(32).toString('hex')\n const tokenHash = await hash(raw, BCRYPT_COST)\n const tokenPrefix = raw.slice(0, 12)\n\n const token = this.em.create(ScimToken, {\n
|
|
5
|
-
"mappings": "AAAA,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import { randomBytes } from 'node:crypto'\nimport type { CacheStrategy } from '@open-mercato/cache'\nimport { runWithCacheTenant } from '@open-mercato/cache'\nimport { readRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\nimport { SCIM_ADMISSION_TTL_MS, scimAdmissionCacheKey, scimAdmissionTokenTag, scimAdmissionTokenKey, scimTokenLookupHash } from '../lib/scim-admission-cache'\nimport type { RequiredEntityData } from '@mikro-orm/core'\nimport { EntityManager } from '@mikro-orm/postgresql'\nimport { hash, compare } from 'bcryptjs'\nimport { ScimToken, SsoConfig } from '../data/entities'\nimport type { SsoAdminScope } from './ssoConfigService'\n\nconst BCRYPT_COST = 10\nconst TOKEN_PREFIX = 'omscim_'\n\nexport interface ScimTokenPublic {\n id: string\n ssoConfigId: string\n name: string\n tokenPrefix: string\n isActive: boolean\n createdBy: string | null\n createdAt: Date\n}\n\nexport interface ScimTokenCreateResult {\n id: string\n token: string\n prefix: string\n name: string\n}\n\nexport class ScimTokenService {\n constructor(private em: EntityManager, private cache?: CacheStrategy) {}\n\n async generateToken(\n ssoConfigId: string,\n name: string,\n scope: SsoAdminScope,\n ): Promise<ScimTokenCreateResult> {\n const where: Record<string, unknown> = { id: ssoConfigId, deletedAt: null }\n if (!scope.isSuperAdmin) {\n if (!scope.organizationId) throw new ScimTokenError('Organization context is required', 403)\n where.organizationId = scope.organizationId\n }\n const config = await this.em.findOne(SsoConfig, where)\n if (!config) throw new ScimTokenError('SSO configuration not found', 404)\n if (config.jitEnabled) {\n throw new ScimTokenError('Cannot create SCIM tokens while JIT provisioning is enabled. Disable JIT first.', 409)\n }\n\n const raw = TOKEN_PREFIX + randomBytes(32).toString('hex')\n const tokenHash = await hash(raw, BCRYPT_COST)\n const tokenPrefix = raw.slice(0, 12)\n\n try {\n const token = this.em.create(ScimToken, {\n ssoConfigId,\n name,\n tokenHash,\n tokenLookupHash: scimTokenLookupHash(raw),\n tokenPrefix,\n isActive: true,\n createdBy: null,\n tenantId: config.tenantId ?? null,\n organizationId: config.organizationId,\n } as RequiredEntityData<ScimToken>)\n await this.em.persist(token).flush()\n return { id: token.id, token: raw, prefix: tokenPrefix, name }\n } catch {\n const error = new Error('[internal] SCIM token persistence unavailable')\n try {\n getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_token_persistence_unavailable' })\n } catch {}\n throw error\n }\n }\n\n async verifyToken(rawToken: string): Promise<{\n ssoConfigId: string\n organizationId: string\n tenantId: string | null\n } | null> {\n const prefix = rawToken.slice(0, 12)\n\n const candidates = await this.em.find(ScimToken, {\n tokenPrefix: prefix,\n isActive: true,\n })\n\n if (candidates.length === 0) {\n await hash(rawToken, BCRYPT_COST)\n return null\n }\n\n for (const candidate of candidates) {\n const tokenHash = candidate.tokenHash\n const isValid = await compare(rawToken, tokenHash)\n if (isValid) {\n if (candidate.tokenLookupHash == null) {\n const tokenLookupHash = scimTokenLookupHash(rawToken)\n const updated = await this.em.nativeUpdate(ScimToken, {\n id: candidate.id,\n tenantId: candidate.tenantId ?? null,\n organizationId: candidate.organizationId,\n ssoConfigId: candidate.ssoConfigId,\n tokenHash,\n isActive: true,\n $or: [{ tokenLookupHash: null }, { tokenLookupHash }],\n }, { tokenLookupHash }).catch(() => {\n const error = new ScimTokenError('[internal] SCIM token enrollment unavailable', 503)\n try {\n getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_enrollment_unavailable' })\n } catch {}\n throw error\n })\n if (updated === 0) return null\n }\n const cache = this.cache\n if (cache && readRateLimitConfig().enabled) {\n try {\n await runWithCacheTenant(null, () => cache.set(\n scimAdmissionCacheKey(rawToken),\n scimAdmissionTokenKey(candidate),\n { ttl: SCIM_ADMISSION_TTL_MS, tags: [scimAdmissionTokenTag(candidate.id)] },\n ))\n } catch (error) {\n try {\n getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_admission_cache_write_failed' })\n } catch {}\n }\n }\n return {\n ssoConfigId: candidate.ssoConfigId,\n organizationId: candidate.organizationId,\n tenantId: candidate.tenantId ?? null,\n }\n }\n }\n\n return null\n }\n\n async revokeToken(tokenId: string, scope: SsoAdminScope): Promise<void> {\n const where: Record<string, unknown> = { id: tokenId }\n if (!scope.isSuperAdmin) where.organizationId = scope.organizationId\n\n const token = await this.em.findOne(ScimToken, where)\n if (!token) throw new ScimTokenError('SCIM token not found', 404)\n\n token.isActive = false\n await this.em.flush()\n const cache = this.cache\n if (cache) {\n try {\n await runWithCacheTenant(null, () => cache.deleteByTags([scimAdmissionTokenTag(token.id)]))\n } catch (error) {\n try {\n getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_admission_cache_invalidation_failed' })\n } catch {}\n }\n }\n }\n\n async listTokens(ssoConfigId: string, scope: SsoAdminScope): Promise<ScimTokenPublic[]> {\n const where: Record<string, unknown> = { ssoConfigId }\n if (!scope.isSuperAdmin) where.organizationId = scope.organizationId\n\n const tokens = await this.em.find(ScimToken, where, {\n orderBy: { createdAt: 'desc' },\n })\n\n return tokens.map((t) => ({\n id: t.id,\n ssoConfigId: t.ssoConfigId,\n name: t.name,\n tokenPrefix: t.tokenPrefix,\n isActive: t.isActive,\n createdBy: t.createdBy ?? null,\n createdAt: t.createdAt,\n }))\n }\n}\n\nexport class ScimTokenError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number,\n ) {\n super(message)\n this.name = 'ScimTokenError'\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAE5B,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAS,uBAAuB,uBAAuB,uBAAuB,uBAAuB,2BAA2B;AAGhI,SAAS,MAAM,eAAe;AAC9B,SAAS,WAAW,iBAAiB;AAGrC,MAAM,cAAc;AACpB,MAAM,eAAe;AAmBd,MAAM,iBAAiB;AAAA,EAC5B,YAAoB,IAA2B,OAAuB;AAAlD;AAA2B;AAAA,EAAwB;AAAA,EAEvE,MAAM,cACJ,aACA,MACA,OACgC;AAChC,UAAM,QAAiC,EAAE,IAAI,aAAa,WAAW,KAAK;AAC1E,QAAI,CAAC,MAAM,cAAc;AACvB,UAAI,CAAC,MAAM,eAAgB,OAAM,IAAI,eAAe,oCAAoC,GAAG;AAC3F,YAAM,iBAAiB,MAAM;AAAA,IAC/B;AACA,UAAM,SAAS,MAAM,KAAK,GAAG,QAAQ,WAAW,KAAK;AACrD,QAAI,CAAC,OAAQ,OAAM,IAAI,eAAe,+BAA+B,GAAG;AACxE,QAAI,OAAO,YAAY;AACrB,YAAM,IAAI,eAAe,mFAAmF,GAAG;AAAA,IACjH;AAEA,UAAM,MAAM,eAAe,YAAY,EAAE,EAAE,SAAS,KAAK;AACzD,UAAM,YAAY,MAAM,KAAK,KAAK,WAAW;AAC7C,UAAM,cAAc,IAAI,MAAM,GAAG,EAAE;AAEnC,QAAI;AACF,YAAM,QAAQ,KAAK,GAAG,OAAO,WAAW;AAAA,QACtC;AAAA,QACA;AAAA,QACA;AAAA,QACA,iBAAiB,oBAAoB,GAAG;AAAA,QACxC;AAAA,QACA,UAAU;AAAA,QACV,WAAW;AAAA,QACX,UAAU,OAAO,YA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AAC;AAAA,QACnH,QAAQ;AAAA,QAAC;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,aAAqB,OAAkD;AACtF,UAAM,QAAiC,EAAE,YAAY;AACrD,QAAI,CAAC,MAAM,aAAc,OAAM,iBAAiB,MAAM;AAEtD,UAAM,SAAS,MAAM,KAAK,GAAG,KAAK,WAAW,OAAO;AAAA,MAClD,SAAS,EAAE,WAAW,OAAO;AAAA,IAC/B,CAAC;AAED,WAAO,OAAO,IAAI,CAAC,OAAO;AAAA,MACxB,IAAI,EAAE;AAAA,MACN,aAAa,EAAE;AAAA,MACf,MAAM,EAAE;AAAA,MACR,aAAa,EAAE;AAAA,MACf,UAAU,EAAE;AAAA,MACZ,WAAW,EAAE,aAAa;AAAA,MAC1B,WAAW,EAAE;AAAA,IACf,EAAE;AAAA,EACJ;AACF;AAEO,MAAM,uBAAuB,MAAM;AAAA,EACxC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/enterprise",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7813.1.83931e7add",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -70,12 +70,12 @@
|
|
|
70
70
|
"@dnd-kit/core": "^6.3.1",
|
|
71
71
|
"@dnd-kit/sortable": "^10.0.0",
|
|
72
72
|
"@dnd-kit/utilities": "^3.2.2",
|
|
73
|
-
"@open-mercato/ai-assistant": "0.10.1-develop.
|
|
74
|
-
"@open-mercato/core": "0.10.1-develop.
|
|
75
|
-
"@open-mercato/queue": "0.10.1-develop.
|
|
76
|
-
"@open-mercato/scheduler": "0.10.1-develop.
|
|
77
|
-
"@open-mercato/ui": "0.10.1-develop.
|
|
78
|
-
"@open-mercato/web-research": "0.10.1-develop.
|
|
73
|
+
"@open-mercato/ai-assistant": "0.10.1-develop.7813.1.83931e7add",
|
|
74
|
+
"@open-mercato/core": "0.10.1-develop.7813.1.83931e7add",
|
|
75
|
+
"@open-mercato/queue": "0.10.1-develop.7813.1.83931e7add",
|
|
76
|
+
"@open-mercato/scheduler": "0.10.1-develop.7813.1.83931e7add",
|
|
77
|
+
"@open-mercato/ui": "0.10.1-develop.7813.1.83931e7add",
|
|
78
|
+
"@open-mercato/web-research": "0.10.1-develop.7813.1.83931e7add",
|
|
79
79
|
"@simplewebauthn/browser": "^13.3.0",
|
|
80
80
|
"@simplewebauthn/server": "^13.3.2",
|
|
81
81
|
"@simplewebauthn/types": "^12.0.0",
|
|
@@ -87,13 +87,13 @@
|
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@mikro-orm/core": "^7.0.14",
|
|
90
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
90
|
+
"@open-mercato/shared": "0.10.1-develop.7813.1.83931e7add",
|
|
91
91
|
"react": "^19.0.0",
|
|
92
92
|
"react-dom": "^19.0.0",
|
|
93
93
|
"zod": ">=3.23.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
96
|
+
"@open-mercato/shared": "0.10.1-develop.7813.1.83931e7add",
|
|
97
97
|
"@types/jest": "^30.0.0",
|
|
98
98
|
"@types/react": "^19.2.18",
|
|
99
99
|
"@types/react-dom": "^19.2.5",
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
2
|
-
import { ScimTokenService } from '../../services/scimTokenService'
|
|
2
|
+
import { ScimTokenError, ScimTokenService } from '../../services/scimTokenService'
|
|
3
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
4
|
+
import { RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK } from '@open-mercato/shared/lib/ratelimit/helpers'
|
|
3
5
|
import { SsoConfig } from '../../data/entities'
|
|
4
6
|
import { buildScimError, scimJson } from '../../lib/scim-response'
|
|
5
7
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
8
|
+
import { checkScimRateLimit } from './rate-limit'
|
|
6
9
|
|
|
7
10
|
export interface ScimScope {
|
|
8
11
|
ssoConfigId: string
|
|
@@ -15,6 +18,9 @@ export async function resolveScimContext(req: Request): Promise<
|
|
|
15
18
|
| { ok: true; scope: ScimScope }
|
|
16
19
|
| { ok: false; response: Response }
|
|
17
20
|
> {
|
|
21
|
+
const rateLimitError = await checkScimRateLimit(req)
|
|
22
|
+
if (rateLimitError) return { ok: false, response: rateLimitError }
|
|
23
|
+
|
|
18
24
|
const authHeader = req.headers.get('authorization')
|
|
19
25
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
20
26
|
return {
|
|
@@ -36,7 +42,17 @@ export async function resolveScimContext(req: Request): Promise<
|
|
|
36
42
|
|
|
37
43
|
const container = await createRequestContainer()
|
|
38
44
|
const scimTokenService = container.resolve<ScimTokenService>('scimTokenService')
|
|
39
|
-
|
|
45
|
+
let verified: Awaited<ReturnType<ScimTokenService['verifyToken']>>
|
|
46
|
+
try {
|
|
47
|
+
verified = await scimTokenService.verifyToken(rawToken)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (!(error instanceof ScimTokenError) || error.statusCode !== 503) throw error
|
|
50
|
+
const { translate } = await resolveTranslations()
|
|
51
|
+
return {
|
|
52
|
+
ok: false,
|
|
53
|
+
response: scimJson(buildScimError(503, translate(RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK)), 503),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
40
56
|
|
|
41
57
|
if (!verified) {
|
|
42
58
|
return {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
3
|
+
import type { CacheStrategy } from '@open-mercato/cache'
|
|
4
|
+
import { getCachedRateLimiterService } from '@open-mercato/core/bootstrap'
|
|
5
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
6
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
7
|
+
import { readEndpointRateLimitConfig, readRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'
|
|
8
|
+
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
9
|
+
import {
|
|
10
|
+
checkRateLimit,
|
|
11
|
+
getClientIp,
|
|
12
|
+
RATE_LIMIT_ERROR_KEY,
|
|
13
|
+
RATE_LIMIT_ERROR_FALLBACK,
|
|
14
|
+
RATE_LIMIT_FALLBACK_KEY,
|
|
15
|
+
RATE_LIMIT_UNAVAILABLE_KEY,
|
|
16
|
+
RATE_LIMIT_UNAVAILABLE_FALLBACK,
|
|
17
|
+
} from '@open-mercato/shared/lib/ratelimit/helpers'
|
|
18
|
+
import { buildScimError, scimJson } from '../../lib/scim-response'
|
|
19
|
+
import { readScimAdmissionKey, scimAdmissionTokenKey, scimTokenLookupHash } from '../../lib/scim-admission-cache'
|
|
20
|
+
import { ScimToken } from '../../data/entities'
|
|
21
|
+
|
|
22
|
+
const admissions = new WeakMap<Request, Promise<Response | null>>()
|
|
23
|
+
|
|
24
|
+
export function checkScimRateLimit(req: Request): Promise<Response | null> {
|
|
25
|
+
const existing = admissions.get(req)
|
|
26
|
+
if (existing) return existing
|
|
27
|
+
const admission = consumeScimRateLimit(req)
|
|
28
|
+
admissions.set(req, admission)
|
|
29
|
+
return admission
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function consumeScimRateLimit(req: Request): Promise<Response | null> {
|
|
33
|
+
let limited: Response | null = new Response(null, { status: 503 })
|
|
34
|
+
try {
|
|
35
|
+
if (!readRateLimitConfig().enabled) return null
|
|
36
|
+
const limiter = getCachedRateLimiterService()
|
|
37
|
+
const config = readEndpointRateLimitConfig('SCIM', {
|
|
38
|
+
points: 10,
|
|
39
|
+
duration: 1,
|
|
40
|
+
keyPrefix: 'sso-scim',
|
|
41
|
+
})
|
|
42
|
+
if (limiter) {
|
|
43
|
+
const key = await resolveScimRateLimitKey(req, getClientIp(req, limiter.trustProxyDepth))
|
|
44
|
+
limited = await checkRateLimit(limiter, config, key, RATE_LIMIT_ERROR_FALLBACK, { failClosed: true })
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
try {
|
|
48
|
+
getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_admission_unavailable' })
|
|
49
|
+
} catch {
|
|
50
|
+
return buildScimRateLimitResponse(new Response(null, { status: 503 }))
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!limited) return null
|
|
54
|
+
return buildScimRateLimitResponse(limited)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function buildScimRateLimitResponse(limited: Response): Promise<Response> {
|
|
58
|
+
const { translate } = await resolveTranslations()
|
|
59
|
+
const detail = limited.status === 429
|
|
60
|
+
? translate(RATE_LIMIT_ERROR_KEY, RATE_LIMIT_ERROR_FALLBACK)
|
|
61
|
+
: translate(RATE_LIMIT_UNAVAILABLE_KEY, RATE_LIMIT_UNAVAILABLE_FALLBACK)
|
|
62
|
+
const response = scimJson(buildScimError(limited.status, detail), limited.status)
|
|
63
|
+
limited.headers.forEach((value, name) => {
|
|
64
|
+
if (name !== 'content-type') response.headers.set(name, value)
|
|
65
|
+
})
|
|
66
|
+
return response
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function resolveScimRateLimitKey(req: Request, clientIp: string | null): Promise<string> {
|
|
70
|
+
if (new URL(req.url).pathname.replace(/\/+$/, '').endsWith('/sso/scim/v2/ServiceProviderConfig')) {
|
|
71
|
+
return `discovery:${clientIp ?? RATE_LIMIT_FALLBACK_KEY}`
|
|
72
|
+
}
|
|
73
|
+
const authorization = req.headers.get('authorization')
|
|
74
|
+
const rawToken = authorization?.startsWith('Bearer ') ? authorization.slice(7) : ''
|
|
75
|
+
if (/^omscim_[0-9a-f]{64}$/.test(rawToken)) {
|
|
76
|
+
const container = await createRequestContainer()
|
|
77
|
+
const cache = container.resolve<CacheStrategy>('cache')
|
|
78
|
+
const verifiedKey = await readScimAdmissionKey(cache, rawToken)
|
|
79
|
+
if (verifiedKey) return verifiedKey
|
|
80
|
+
const em = container.resolve<EntityManager>('em')
|
|
81
|
+
const token = await findOneWithDecryption(em, ScimToken, {
|
|
82
|
+
tokenLookupHash: scimTokenLookupHash(rawToken),
|
|
83
|
+
isActive: true,
|
|
84
|
+
}, { fields: ['id', 'tenantId', 'organizationId'] }).catch(() => {
|
|
85
|
+
throw new Error('[internal] SCIM fingerprint lookup unavailable')
|
|
86
|
+
})
|
|
87
|
+
if (token) return scimAdmissionTokenKey(token)
|
|
88
|
+
}
|
|
89
|
+
return clientIp ?? RATE_LIMIT_FALLBACK_KEY
|
|
90
|
+
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
2
2
|
import { scimJson } from '../../../../lib/scim-response'
|
|
3
|
+
import { checkScimRateLimit } from '../../rate-limit'
|
|
3
4
|
|
|
4
5
|
export const metadata = { requireAuth: false }
|
|
6
|
+
export const beforeAuth = checkScimRateLimit
|
|
7
|
+
|
|
8
|
+
export async function GET(req: Request) {
|
|
9
|
+
const rateLimitError = await checkScimRateLimit(req)
|
|
10
|
+
if (rateLimitError) return rateLimitError
|
|
5
11
|
|
|
6
|
-
export async function GET() {
|
|
7
12
|
return scimJson({
|
|
8
13
|
schemas: ['urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig'],
|
|
9
14
|
documentationUri: 'https://open-mercato.com/docs/scim',
|
|
@@ -34,7 +39,10 @@ export const openApi: OpenApiRouteDoc = {
|
|
|
34
39
|
description: 'Returns SCIM 2.0 ServiceProviderConfig. No authentication required — used by identity providers during connection testing.',
|
|
35
40
|
tags: ['SSO', 'SCIM'],
|
|
36
41
|
responses: [{ status: 200, description: 'SCIM ServiceProviderConfig' }],
|
|
37
|
-
errors: [
|
|
42
|
+
errors: [
|
|
43
|
+
{ status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },
|
|
44
|
+
{ status: 503, description: 'Rate limiter unavailable' },
|
|
45
|
+
],
|
|
38
46
|
},
|
|
39
47
|
},
|
|
40
48
|
}
|
|
@@ -7,6 +7,7 @@ import { scimJson } from '../../../../../lib/scim-response'
|
|
|
7
7
|
import { handleScimApiError } from '../../../../error-handler'
|
|
8
8
|
|
|
9
9
|
export const metadata = { requireAuth: false }
|
|
10
|
+
export { checkScimRateLimit as beforeAuth } from '../../../rate-limit'
|
|
10
11
|
|
|
11
12
|
type RouteContext = { params: Promise<{ id: string }> }
|
|
12
13
|
|
|
@@ -76,6 +77,8 @@ export const openApi: OpenApiRouteDoc = {
|
|
|
76
77
|
errors: [
|
|
77
78
|
{ status: 401, description: 'Unauthorized' },
|
|
78
79
|
{ status: 404, description: 'User not found' },
|
|
80
|
+
{ status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },
|
|
81
|
+
{ status: 503, description: 'Rate limiter unavailable' },
|
|
79
82
|
],
|
|
80
83
|
},
|
|
81
84
|
PATCH: {
|
|
@@ -87,6 +90,8 @@ export const openApi: OpenApiRouteDoc = {
|
|
|
87
90
|
{ status: 400, description: 'Invalid PatchOp' },
|
|
88
91
|
{ status: 401, description: 'Unauthorized' },
|
|
89
92
|
{ status: 404, description: 'User not found' },
|
|
93
|
+
{ status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },
|
|
94
|
+
{ status: 503, description: 'Rate limiter unavailable' },
|
|
90
95
|
],
|
|
91
96
|
},
|
|
92
97
|
DELETE: {
|
|
@@ -97,6 +102,8 @@ export const openApi: OpenApiRouteDoc = {
|
|
|
97
102
|
errors: [
|
|
98
103
|
{ status: 401, description: 'Unauthorized' },
|
|
99
104
|
{ status: 404, description: 'User not found' },
|
|
105
|
+
{ status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },
|
|
106
|
+
{ status: 503, description: 'Rate limiter unavailable' },
|
|
100
107
|
],
|
|
101
108
|
},
|
|
102
109
|
},
|
|
@@ -7,6 +7,7 @@ import { scimUserPayloadSchema } from '../../../../data/validators'
|
|
|
7
7
|
import { buildScimError, scimJson as scimJsonResponse } from '../../../../lib/scim-response'
|
|
8
8
|
|
|
9
9
|
export const metadata = { requireAuth: false }
|
|
10
|
+
export { checkScimRateLimit as beforeAuth } from '../../rate-limit'
|
|
10
11
|
|
|
11
12
|
export async function POST(req: Request) {
|
|
12
13
|
try {
|
|
@@ -78,6 +79,8 @@ export const openApi: OpenApiRouteDoc = {
|
|
|
78
79
|
{ status: 401, description: 'Unauthorized' },
|
|
79
80
|
{ status: 403, description: 'SSO config inactive' },
|
|
80
81
|
{ status: 409, description: 'Conflict — user already linked' },
|
|
82
|
+
{ status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },
|
|
83
|
+
{ status: 503, description: 'Rate limiter unavailable' },
|
|
81
84
|
],
|
|
82
85
|
},
|
|
83
86
|
GET: {
|
|
@@ -88,6 +91,8 @@ export const openApi: OpenApiRouteDoc = {
|
|
|
88
91
|
errors: [
|
|
89
92
|
{ status: 401, description: 'Unauthorized' },
|
|
90
93
|
{ status: 403, description: 'SSO config inactive' },
|
|
94
|
+
{ status: 429, description: 'SCIM request limit exceeded; retry after Retry-After seconds' },
|
|
95
|
+
{ status: 503, description: 'Rate limiter unavailable' },
|
|
91
96
|
],
|
|
92
97
|
},
|
|
93
98
|
},
|
|
@@ -131,6 +131,10 @@ export class ScimToken {
|
|
|
131
131
|
@Property({ name: 'token_hash', type: 'text' })
|
|
132
132
|
tokenHash!: string
|
|
133
133
|
|
|
134
|
+
@Property({ name: 'token_lookup_hash', type: 'text', nullable: true })
|
|
135
|
+
@Index({ name: 'scim_tokens_token_lookup_hash_idx' })
|
|
136
|
+
tokenLookupHash?: string | null
|
|
137
|
+
|
|
134
138
|
@Property({ name: 'token_prefix', type: 'text' })
|
|
135
139
|
tokenPrefix!: string
|
|
136
140
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import type { CacheStrategy } from '@open-mercato/cache'
|
|
3
|
+
import { runWithCacheTenant } from '@open-mercato/cache'
|
|
4
|
+
|
|
5
|
+
export const SCIM_ADMISSION_TTL_MS = 30_000
|
|
6
|
+
|
|
7
|
+
export function scimTokenLookupHash(rawToken: string): string {
|
|
8
|
+
return createHash('sha256').update(rawToken).digest('hex')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function scimAdmissionCacheKey(rawToken: string): string {
|
|
12
|
+
return `sso:scim-admission:${scimTokenLookupHash(rawToken)}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function scimAdmissionTokenKey(token: { id: string; tenantId?: string | null; organizationId: string }): string {
|
|
16
|
+
return `token:${token.tenantId ?? 'global'}:${token.organizationId}:${token.id}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function scimAdmissionTokenTag(tokenId: string): string {
|
|
20
|
+
return `sso:scim-admission:token:${tokenId}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function readScimAdmissionKey(cache: CacheStrategy, rawToken: string): Promise<string | null> {
|
|
24
|
+
const cached = await runWithCacheTenant(null, () => cache.get(scimAdmissionCacheKey(rawToken)))
|
|
25
|
+
return typeof cached === 'string' && cached.startsWith('token:') ? cached : null
|
|
26
|
+
}
|
|
@@ -241,6 +241,15 @@
|
|
|
241
241
|
"nullable": false,
|
|
242
242
|
"length": 6,
|
|
243
243
|
"mappedType": "datetime"
|
|
244
|
+
},
|
|
245
|
+
"token_lookup_hash": {
|
|
246
|
+
"name": "token_lookup_hash",
|
|
247
|
+
"type": "text",
|
|
248
|
+
"unsigned": false,
|
|
249
|
+
"autoincrement": false,
|
|
250
|
+
"primary": false,
|
|
251
|
+
"nullable": true,
|
|
252
|
+
"mappedType": "text"
|
|
244
253
|
}
|
|
245
254
|
},
|
|
246
255
|
"name": "scim_tokens",
|
|
@@ -275,6 +284,16 @@
|
|
|
275
284
|
"constraint": true,
|
|
276
285
|
"primary": true,
|
|
277
286
|
"unique": true
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"keyName": "scim_tokens_token_lookup_hash_idx",
|
|
290
|
+
"columnNames": [
|
|
291
|
+
"token_lookup_hash"
|
|
292
|
+
],
|
|
293
|
+
"composite": false,
|
|
294
|
+
"constraint": false,
|
|
295
|
+
"primary": false,
|
|
296
|
+
"unique": false
|
|
278
297
|
}
|
|
279
298
|
],
|
|
280
299
|
"checks": [],
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Migration } from '@mikro-orm/migrations'
|
|
2
|
+
|
|
3
|
+
export class Migration20261029160000_scim_token_lookup_hash extends Migration {
|
|
4
|
+
override async up(): Promise<void> {
|
|
5
|
+
this.addSql('alter table "scim_tokens" add column "token_lookup_hash" text null;')
|
|
6
|
+
this.addSql('create index "scim_tokens_token_lookup_hash_idx" on "scim_tokens" ("token_lookup_hash");')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
override async down(): Promise<void> {
|
|
10
|
+
this.addSql('drop index if exists "scim_tokens_token_lookup_hash_idx";')
|
|
11
|
+
this.addSql('alter table "scim_tokens" drop column "token_lookup_hash";')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto'
|
|
2
|
+
import type { CacheStrategy } from '@open-mercato/cache'
|
|
3
|
+
import { runWithCacheTenant } from '@open-mercato/cache'
|
|
4
|
+
import { readRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'
|
|
5
|
+
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
6
|
+
import { SCIM_ADMISSION_TTL_MS, scimAdmissionCacheKey, scimAdmissionTokenTag, scimAdmissionTokenKey, scimTokenLookupHash } from '../lib/scim-admission-cache'
|
|
2
7
|
import type { RequiredEntityData } from '@mikro-orm/core'
|
|
3
8
|
import { EntityManager } from '@mikro-orm/postgresql'
|
|
4
9
|
import { hash, compare } from 'bcryptjs'
|
|
@@ -26,7 +31,7 @@ export interface ScimTokenCreateResult {
|
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export class ScimTokenService {
|
|
29
|
-
constructor(private em: EntityManager) {}
|
|
34
|
+
constructor(private em: EntityManager, private cache?: CacheStrategy) {}
|
|
30
35
|
|
|
31
36
|
async generateToken(
|
|
32
37
|
ssoConfigId: string,
|
|
@@ -48,20 +53,27 @@ export class ScimTokenService {
|
|
|
48
53
|
const tokenHash = await hash(raw, BCRYPT_COST)
|
|
49
54
|
const tokenPrefix = raw.slice(0, 12)
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
try {
|
|
57
|
+
const token = this.em.create(ScimToken, {
|
|
58
|
+
ssoConfigId,
|
|
59
|
+
name,
|
|
60
|
+
tokenHash,
|
|
61
|
+
tokenLookupHash: scimTokenLookupHash(raw),
|
|
62
|
+
tokenPrefix,
|
|
63
|
+
isActive: true,
|
|
64
|
+
createdBy: null,
|
|
65
|
+
tenantId: config.tenantId ?? null,
|
|
66
|
+
organizationId: config.organizationId,
|
|
67
|
+
} as RequiredEntityData<ScimToken>)
|
|
68
|
+
await this.em.persist(token).flush()
|
|
69
|
+
return { id: token.id, token: raw, prefix: tokenPrefix, name }
|
|
70
|
+
} catch {
|
|
71
|
+
const error = new Error('[internal] SCIM token persistence unavailable')
|
|
72
|
+
try {
|
|
73
|
+
getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_token_persistence_unavailable' })
|
|
74
|
+
} catch {}
|
|
75
|
+
throw error
|
|
76
|
+
}
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
async verifyToken(rawToken: string): Promise<{
|
|
@@ -82,8 +94,42 @@ export class ScimTokenService {
|
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
for (const candidate of candidates) {
|
|
85
|
-
const
|
|
97
|
+
const tokenHash = candidate.tokenHash
|
|
98
|
+
const isValid = await compare(rawToken, tokenHash)
|
|
86
99
|
if (isValid) {
|
|
100
|
+
if (candidate.tokenLookupHash == null) {
|
|
101
|
+
const tokenLookupHash = scimTokenLookupHash(rawToken)
|
|
102
|
+
const updated = await this.em.nativeUpdate(ScimToken, {
|
|
103
|
+
id: candidate.id,
|
|
104
|
+
tenantId: candidate.tenantId ?? null,
|
|
105
|
+
organizationId: candidate.organizationId,
|
|
106
|
+
ssoConfigId: candidate.ssoConfigId,
|
|
107
|
+
tokenHash,
|
|
108
|
+
isActive: true,
|
|
109
|
+
$or: [{ tokenLookupHash: null }, { tokenLookupHash }],
|
|
110
|
+
}, { tokenLookupHash }).catch(() => {
|
|
111
|
+
const error = new ScimTokenError('[internal] SCIM token enrollment unavailable', 503)
|
|
112
|
+
try {
|
|
113
|
+
getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_enrollment_unavailable' })
|
|
114
|
+
} catch {}
|
|
115
|
+
throw error
|
|
116
|
+
})
|
|
117
|
+
if (updated === 0) return null
|
|
118
|
+
}
|
|
119
|
+
const cache = this.cache
|
|
120
|
+
if (cache && readRateLimitConfig().enabled) {
|
|
121
|
+
try {
|
|
122
|
+
await runWithCacheTenant(null, () => cache.set(
|
|
123
|
+
scimAdmissionCacheKey(rawToken),
|
|
124
|
+
scimAdmissionTokenKey(candidate),
|
|
125
|
+
{ ttl: SCIM_ADMISSION_TTL_MS, tags: [scimAdmissionTokenTag(candidate.id)] },
|
|
126
|
+
))
|
|
127
|
+
} catch (error) {
|
|
128
|
+
try {
|
|
129
|
+
getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_admission_cache_write_failed' })
|
|
130
|
+
} catch {}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
87
133
|
return {
|
|
88
134
|
ssoConfigId: candidate.ssoConfigId,
|
|
89
135
|
organizationId: candidate.organizationId,
|
|
@@ -104,6 +150,16 @@ export class ScimTokenService {
|
|
|
104
150
|
|
|
105
151
|
token.isActive = false
|
|
106
152
|
await this.em.flush()
|
|
153
|
+
const cache = this.cache
|
|
154
|
+
if (cache) {
|
|
155
|
+
try {
|
|
156
|
+
await runWithCacheTenant(null, () => cache.deleteByTags([scimAdmissionTokenTag(token.id)]))
|
|
157
|
+
} catch (error) {
|
|
158
|
+
try {
|
|
159
|
+
getTelemetryRuntime()?.reportError(error, { module: 'sso', code: 'sso.scim_admission_cache_invalidation_failed' })
|
|
160
|
+
} catch {}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
107
163
|
}
|
|
108
164
|
|
|
109
165
|
async listTokens(ssoConfigId: string, scope: SsoAdminScope): Promise<ScimTokenPublic[]> {
|