@dads-framework/identity 0.0.0-stage → 0.2.0
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/LICENSE.md +21 -0
- package/README.md +145 -2
- package/dist/identity-types.d.ts +25 -0
- package/dist/identity-types.d.ts.map +1 -0
- package/dist/identity-types.js +2 -0
- package/dist/identity-types.js.map +1 -0
- package/dist/identity.tsbuildinfo +1 -0
- package/dist/impersonation/audit.d.ts +15 -0
- package/dist/impersonation/audit.d.ts.map +1 -0
- package/dist/impersonation/audit.js +24 -0
- package/dist/impersonation/audit.js.map +1 -0
- package/dist/impersonation/create-impersonation.d.ts +3 -0
- package/dist/impersonation/create-impersonation.d.ts.map +1 -0
- package/dist/impersonation/create-impersonation.js +170 -0
- package/dist/impersonation/create-impersonation.js.map +1 -0
- package/dist/impersonation/index.d.ts +4 -0
- package/dist/impersonation/index.d.ts.map +1 -0
- package/dist/impersonation/index.js +3 -0
- package/dist/impersonation/index.js.map +1 -0
- package/dist/impersonation/types.d.ts +56 -0
- package/dist/impersonation/types.d.ts.map +1 -0
- package/dist/impersonation/types.js +2 -0
- package/dist/impersonation/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/normalize-identity-email.d.ts +3 -0
- package/dist/normalize-identity-email.d.ts.map +1 -0
- package/dist/normalize-identity-email.js +9 -0
- package/dist/normalize-identity-email.js.map +1 -0
- package/dist/scim/directory.d.ts +55 -0
- package/dist/scim/directory.d.ts.map +1 -0
- package/dist/scim/directory.js +14 -0
- package/dist/scim/directory.js.map +1 -0
- package/dist/scim/discovery.d.ts +2 -0
- package/dist/scim/discovery.d.ts.map +1 -0
- package/dist/scim/discovery.js +128 -0
- package/dist/scim/discovery.js.map +1 -0
- package/dist/scim/group-data.d.ts +5 -0
- package/dist/scim/group-data.d.ts.map +1 -0
- package/dist/scim/group-data.js +38 -0
- package/dist/scim/group-data.js.map +1 -0
- package/dist/scim/group-directory.d.ts +33 -0
- package/dist/scim/group-directory.d.ts.map +1 -0
- package/dist/scim/group-directory.js +2 -0
- package/dist/scim/group-directory.js.map +1 -0
- package/dist/scim/group-handler.d.ts +3 -0
- package/dist/scim/group-handler.d.ts.map +1 -0
- package/dist/scim/group-handler.js +87 -0
- package/dist/scim/group-handler.js.map +1 -0
- package/dist/scim/handler.d.ts +11 -0
- package/dist/scim/handler.d.ts.map +1 -0
- package/dist/scim/handler.js +126 -0
- package/dist/scim/handler.js.map +1 -0
- package/dist/scim/index.d.ts +6 -0
- package/dist/scim/index.d.ts.map +1 -0
- package/dist/scim/index.js +3 -0
- package/dist/scim/index.js.map +1 -0
- package/dist/scim/patch-group.d.ts +3 -0
- package/dist/scim/patch-group.d.ts.map +1 -0
- package/dist/scim/patch-group.js +94 -0
- package/dist/scim/patch-group.js.map +1 -0
- package/dist/scim/patch-operations.d.ts +7 -0
- package/dist/scim/patch-operations.d.ts.map +1 -0
- package/dist/scim/patch-operations.js +33 -0
- package/dist/scim/patch-operations.js.map +1 -0
- package/dist/scim/patch-user.d.ts +3 -0
- package/dist/scim/patch-user.d.ts.map +1 -0
- package/dist/scim/patch-user.js +84 -0
- package/dist/scim/patch-user.js.map +1 -0
- package/dist/scim/protocol.d.ts +23 -0
- package/dist/scim/protocol.d.ts.map +1 -0
- package/dist/scim/protocol.js +114 -0
- package/dist/scim/protocol.js.map +1 -0
- package/dist/scim/resource-projection.d.ts +5 -0
- package/dist/scim/resource-projection.d.ts.map +1 -0
- package/dist/scim/resource-projection.js +35 -0
- package/dist/scim/resource-projection.js.map +1 -0
- package/dist/scim/user-data.d.ts +5 -0
- package/dist/scim/user-data.d.ts.map +1 -0
- package/dist/scim/user-data.js +74 -0
- package/dist/scim/user-data.js.map +1 -0
- package/dist/scim/user-query.d.ts +6 -0
- package/dist/scim/user-query.d.ts.map +1 -0
- package/dist/scim/user-query.js +59 -0
- package/dist/scim/user-query.js.map +1 -0
- package/dist/scim/user-response.d.ts +3 -0
- package/dist/scim/user-response.d.ts.map +1 -0
- package/dist/scim/user-response.js +18 -0
- package/dist/scim/user-response.js.map +1 -0
- package/dist/testing/identity-session-conformance.d.ts +12 -0
- package/dist/testing/identity-session-conformance.d.ts.map +1 -0
- package/dist/testing/identity-session-conformance.js +30 -0
- package/dist/testing/identity-session-conformance.js.map +1 -0
- package/dist/testing/in-memory-identity.d.ts +7 -0
- package/dist/testing/in-memory-identity.d.ts.map +1 -0
- package/dist/testing/in-memory-identity.js +45 -0
- package/dist/testing/in-memory-identity.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +45 -4
- package/src/impersonation/README.md +35 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ScimUserData } from "./directory.js";
|
|
2
|
+
export declare const nameAttributes: ("familyName" | "formatted" | "givenName" | "honorificPrefix" | "honorificSuffix" | "middleName")[];
|
|
3
|
+
export declare function userString(value: unknown): string | undefined;
|
|
4
|
+
export declare function parseScimUser(input: unknown, defaultActive?: boolean): ScimUserData;
|
|
5
|
+
//# sourceMappingURL=user-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-data.d.ts","sourceRoot":"","sources":["../../src/scim/user-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGxE,eAAO,MAAM,cAAc,qGAOY,CAAC;AAExC,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI7D;AA4CD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,aAAa,UAAO,GACnB,YAAY,CAuBd"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { attributes, ScimError } from "./protocol.js";
|
|
2
|
+
export const nameAttributes = [
|
|
3
|
+
"formatted",
|
|
4
|
+
"familyName",
|
|
5
|
+
"givenName",
|
|
6
|
+
"middleName",
|
|
7
|
+
"honorificPrefix",
|
|
8
|
+
"honorificSuffix",
|
|
9
|
+
];
|
|
10
|
+
export function userString(value) {
|
|
11
|
+
if (value === undefined || value === null)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (typeof value === "string")
|
|
14
|
+
return value;
|
|
15
|
+
throw new ScimError(400, "Expected a string attribute.", "invalidValue");
|
|
16
|
+
}
|
|
17
|
+
function parseName(value) {
|
|
18
|
+
if (value === undefined || value === null)
|
|
19
|
+
return undefined;
|
|
20
|
+
const fields = attributes(value);
|
|
21
|
+
return Object.fromEntries(nameAttributes.flatMap((key) => {
|
|
22
|
+
const item = userString(fields[key.toLowerCase()]);
|
|
23
|
+
return item === undefined ? [] : [[key, item]];
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
function parseEmail(value) {
|
|
27
|
+
const fields = attributes(value);
|
|
28
|
+
const email = userString(fields["value"]);
|
|
29
|
+
const type = userString(fields["type"]);
|
|
30
|
+
const display = userString(fields["display"]);
|
|
31
|
+
const primary = fields["primary"];
|
|
32
|
+
if (!email?.trim() ||
|
|
33
|
+
(primary !== undefined && typeof primary !== "boolean")) {
|
|
34
|
+
throw new ScimError(400, "Invalid email attribute.", "invalidValue");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
value: email,
|
|
38
|
+
...(type === undefined ? {} : { type }),
|
|
39
|
+
...(display === undefined ? {} : { display }),
|
|
40
|
+
...(primary === undefined ? {} : { primary }),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function parseEmails(value) {
|
|
44
|
+
if (value === undefined || value === null)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (!Array.isArray(value))
|
|
47
|
+
throw new ScimError(400, "Expected an email list.", "invalidValue");
|
|
48
|
+
const emails = value.map(parseEmail);
|
|
49
|
+
if (emails.filter((email) => email.primary).length > 1) {
|
|
50
|
+
throw new ScimError(400, "Only one email can be primary.", "invalidValue");
|
|
51
|
+
}
|
|
52
|
+
return emails;
|
|
53
|
+
}
|
|
54
|
+
export function parseScimUser(input, defaultActive = true) {
|
|
55
|
+
const fields = attributes(input);
|
|
56
|
+
const userName = userString(fields["username"]);
|
|
57
|
+
const active = fields["active"] ?? defaultActive;
|
|
58
|
+
const externalId = userString(fields["externalid"]);
|
|
59
|
+
const displayName = userString(fields["displayname"]);
|
|
60
|
+
const name = parseName(fields["name"]);
|
|
61
|
+
const emails = parseEmails(fields["emails"]);
|
|
62
|
+
if (!userName?.trim() || typeof active !== "boolean") {
|
|
63
|
+
throw new ScimError(400, "A userName string and a boolean active value are required.", "invalidValue");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
userName,
|
|
67
|
+
active,
|
|
68
|
+
...(externalId === undefined ? {} : { externalId }),
|
|
69
|
+
...(displayName === undefined ? {} : { displayName }),
|
|
70
|
+
...(name === undefined ? {} : { name }),
|
|
71
|
+
...(emails === undefined ? {} : { emails }),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=user-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-data.js","sourceRoot":"","sources":["../../src/scim/user-data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,WAAW;IACX,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;CACoB,CAAC;AAExC,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,8BAA8B,EAAE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,CAAC,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,OAAO,MAAM,KAAK,SAAS,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CACjB,GAAG,EACH,4DAA4D,EAC5D,cAAc,CACf,CAAC;IACJ,CAAC;IACD,OAAO;QACL,QAAQ;QACR,MAAM;QACN,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;QACnD,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;QACrD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QACvC,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ScimUserQuery } from "./directory.js";
|
|
2
|
+
export declare const maxPageSize = 100;
|
|
3
|
+
export declare function parseFilterLiteral(literal: string): unknown;
|
|
4
|
+
export declare function scimUserQuery(params: URLSearchParams): ScimUserQuery;
|
|
5
|
+
export declare function scimPage(params: URLSearchParams): Pick<ScimUserQuery, "startIndex" | "count">;
|
|
6
|
+
//# sourceMappingURL=user-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-query.d.ts","sourceRoot":"","sources":["../../src/scim/user-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpE,eAAO,MAAM,WAAW,MAAM,CAAC;AAuB/B,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO3D;AA+BD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAIpE;AAED,wBAAgB,QAAQ,CACtB,MAAM,EAAE,eAAe,GACtB,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,OAAO,CAAC,CAO7C"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ScimError, userAttributePath } from "./protocol.js";
|
|
2
|
+
export const maxPageSize = 100;
|
|
3
|
+
function filterError() {
|
|
4
|
+
return new ScimError(400, "Expected a supported equality filter.", "invalidFilter");
|
|
5
|
+
}
|
|
6
|
+
function parseFilter(filter) {
|
|
7
|
+
const match = /^([^\s]+)\s+eq\s+("(?:[^"\\]|\\.)*"|true|false)$/i.exec(filter.trim());
|
|
8
|
+
const rawAttribute = match?.[1];
|
|
9
|
+
const literal = match?.[2];
|
|
10
|
+
if (!rawAttribute || !literal)
|
|
11
|
+
throw filterError();
|
|
12
|
+
return equalityFilter(userAttributePath(rawAttribute), parseFilterLiteral(literal));
|
|
13
|
+
}
|
|
14
|
+
export function parseFilterLiteral(literal) {
|
|
15
|
+
try {
|
|
16
|
+
const value = JSON.parse(literal);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw filterError();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function equalityFilter(attribute, value) {
|
|
24
|
+
if (attribute === "active" && typeof value === "boolean")
|
|
25
|
+
return { attribute, value };
|
|
26
|
+
const fields = [
|
|
27
|
+
"id",
|
|
28
|
+
"userName",
|
|
29
|
+
"externalId",
|
|
30
|
+
"displayName",
|
|
31
|
+
"emails.value",
|
|
32
|
+
];
|
|
33
|
+
const canonical = fields.find((key) => key.toLowerCase() === attribute);
|
|
34
|
+
if (!canonical || typeof value !== "string")
|
|
35
|
+
throw filterError();
|
|
36
|
+
return { attribute: canonical, value };
|
|
37
|
+
}
|
|
38
|
+
function integerParameter(params, name, fallback) {
|
|
39
|
+
const value = params.get(name);
|
|
40
|
+
if (value === null)
|
|
41
|
+
return fallback;
|
|
42
|
+
if (/^-?\d+$/.test(value)) {
|
|
43
|
+
const integer = Number(value);
|
|
44
|
+
if (Number.isSafeInteger(integer))
|
|
45
|
+
return integer;
|
|
46
|
+
}
|
|
47
|
+
throw new ScimError(400, `Invalid ${name}.`, "invalidValue");
|
|
48
|
+
}
|
|
49
|
+
export function scimUserQuery(params) {
|
|
50
|
+
const filter = params.get("filter");
|
|
51
|
+
const page = scimPage(params);
|
|
52
|
+
return filter === null ? page : { ...page, filter: parseFilter(filter) };
|
|
53
|
+
}
|
|
54
|
+
export function scimPage(params) {
|
|
55
|
+
const startIndex = Math.max(1, integerParameter(params, "startIndex", 1));
|
|
56
|
+
const count = Math.min(maxPageSize, Math.max(0, integerParameter(params, "count", maxPageSize)));
|
|
57
|
+
return { startIndex, count };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=user-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-query.js","sourceRoot":"","sources":["../../src/scim/user-query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE7D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,SAAS,WAAW;IAClB,OAAO,IAAI,SAAS,CAClB,GAAG,EACH,uCAAuC,EACvC,eAAe,CAChB,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,KAAK,GAAG,mDAAmD,CAAC,IAAI,CACpE,MAAM,CAAC,IAAI,EAAE,CACd,CAAC;IACF,MAAM,YAAY,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,CAAC,YAAY,IAAI,CAAC,OAAO;QAAE,M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C;YAAE,OAAO,OAAO,CAAC;IACpD,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,cAAc,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAuB;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,QAAQ,CACtB,MAAuB;IAEvB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CACpB,WAAW,EACX,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAC5D,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-response.d.ts","sourceRoot":"","sources":["../../src/scim/user-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,eAAe,GAC1B,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CA2B9C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { userSchema } from "./protocol.js";
|
|
2
|
+
import { createResourceProjection } from "./resource-projection.js";
|
|
3
|
+
export function createUserProjection(parameters) {
|
|
4
|
+
const project = createResourceProjection(parameters, userSchema);
|
|
5
|
+
return ({ id, created, lastModified, userName, active, externalId, displayName, name, emails, }, location) => {
|
|
6
|
+
const fields = {
|
|
7
|
+
userName,
|
|
8
|
+
active,
|
|
9
|
+
externalId,
|
|
10
|
+
displayName,
|
|
11
|
+
name,
|
|
12
|
+
emails,
|
|
13
|
+
meta: { resourceType: "User", location, created, lastModified },
|
|
14
|
+
};
|
|
15
|
+
return project(id, fields);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=user-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-response.js","sourceRoot":"","sources":["../../src/scim/user-response.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,UAAU,oBAAoB,CAClC,UAA2B;IAE3B,MAAM,OAAO,GAAG,wBAAwB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACjE,OAAO,CACL,EACE,EAAE,EACF,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACP,EACD,QAAQ,EACR,EAAE;QACF,MAAM,MAAM,GAAG;YACb,QAAQ;YACR,MAAM;YACN,UAAU;YACV,WAAW;YACX,IAAI;YACJ,MAAM;YACN,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE;SAChE,CAAC;QACF,OAAO,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Identity, IdentityAccount } from "../identity-types.js";
|
|
2
|
+
export type IdentitySessionConformance = {
|
|
3
|
+
readonly identity: Identity;
|
|
4
|
+
readonly origin: string;
|
|
5
|
+
readonly activeCookie: string;
|
|
6
|
+
readonly otherCookie: string;
|
|
7
|
+
readonly expiredCookie: string;
|
|
8
|
+
readonly account: IdentityAccount;
|
|
9
|
+
};
|
|
10
|
+
/** Apply the same session laws to a stand-in and a database-backed provider. */
|
|
11
|
+
export declare function verifyIdentitySessionConformance(input: IdentitySessionConformance): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=identity-session-conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-session-conformance.d.ts","sourceRoot":"","sources":["../../src/testing/identity-session-conformance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF,gFAAgF;AAChF,wBAAsB,gCAAgC,CACpD,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
/** Apply the same session laws to a stand-in and a database-backed provider. */
|
|
3
|
+
export async function verifyIdentitySessionConformance(input) {
|
|
4
|
+
const { identity, origin, activeCookie, otherCookie, expiredCookie, account, } = input;
|
|
5
|
+
const active = new Headers({ cookie: activeCookie });
|
|
6
|
+
const other = new Headers({ cookie: otherCookie });
|
|
7
|
+
const expired = new Headers({ cookie: expiredCookie });
|
|
8
|
+
assert.equal(await identity.readSession(new Headers()), null);
|
|
9
|
+
assert.equal(await identity.readSession(expired), null);
|
|
10
|
+
const current = await identity.readSession(active);
|
|
11
|
+
assert.ok(current);
|
|
12
|
+
assert.deepEqual(current.account, account);
|
|
13
|
+
assert.ok(current.expiresAt instanceof Date);
|
|
14
|
+
assert.ok(await identity.readSession(other));
|
|
15
|
+
const projection = await identity.handle(new Request(`${origin}/api/auth/get-session`, { headers: active }));
|
|
16
|
+
assert.equal(projection.status, 200);
|
|
17
|
+
const body = await projection.json();
|
|
18
|
+
assert.deepEqual(body, {
|
|
19
|
+
account,
|
|
20
|
+
expiresAt: current.expiresAt.toISOString(),
|
|
21
|
+
});
|
|
22
|
+
const signedOut = await identity.handle(new Request(`${origin}/api/auth/sign-out`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: new Headers({ cookie: activeCookie, origin }),
|
|
25
|
+
}));
|
|
26
|
+
assert.equal(signedOut.status, 200);
|
|
27
|
+
assert.equal(await identity.readSession(active), null);
|
|
28
|
+
assert.ok(await identity.readSession(other));
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=identity-session-conformance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-session-conformance.js","sourceRoot":"","sources":["../../src/testing/identity-session-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAYxC,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,KAAiC;IAEjC,MAAM,EACJ,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,WAAW,EACX,aAAa,EACb,OAAO,GACR,GAAG,KAAK,CAAC;IACV,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,IAAI,OAAO,CA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AC,CACH,CAAC;IACF,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,MAAM,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,EAAE,CAAC,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Identity, IdentitySession } from "../identity-types.js";
|
|
2
|
+
export type InMemoryIdentitySessions = Readonly<Record<string, IdentitySession>>;
|
|
3
|
+
/** A cookie header value for a session explicitly seeded by a test. */
|
|
4
|
+
export declare function inMemoryIdentityCookie(key: string): string;
|
|
5
|
+
/** A stand-in for the verified-session boundary, driven by a test clock. */
|
|
6
|
+
export declare function inMemoryIdentity(seed: InMemoryIdentitySessions, now: () => Date): Identity;
|
|
7
|
+
//# sourceMappingURL=in-memory-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-identity.d.ts","sourceRoot":"","sources":["../../src/testing/in-memory-identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAC7C,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAChC,CAAC;AAcF,uEAAuE;AACvE,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,wBAAwB,EAC9B,GAAG,EAAE,MAAM,IAAI,GACd,QAAQ,CA8BV"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const SESSION_COOKIE = "dads_fixture_session";
|
|
2
|
+
function tokenFrom(headers) {
|
|
3
|
+
const prefix = `${SESSION_COOKIE}=`;
|
|
4
|
+
return headers
|
|
5
|
+
.get("cookie")
|
|
6
|
+
?.split(";")
|
|
7
|
+
.map((cookie) => cookie.trim())
|
|
8
|
+
.find((cookie) => cookie.startsWith(prefix))
|
|
9
|
+
?.slice(prefix.length);
|
|
10
|
+
}
|
|
11
|
+
/** A cookie header value for a session explicitly seeded by a test. */
|
|
12
|
+
export function inMemoryIdentityCookie(key) {
|
|
13
|
+
return `${SESSION_COOKIE}=${key}`;
|
|
14
|
+
}
|
|
15
|
+
/** A stand-in for the verified-session boundary, driven by a test clock. */
|
|
16
|
+
export function inMemoryIdentity(seed, now) {
|
|
17
|
+
const sessions = new Map(Object.entries(seed));
|
|
18
|
+
function sessionFor(headers) {
|
|
19
|
+
const key = tokenFrom(headers);
|
|
20
|
+
const session = key === undefined ? undefined : sessions.get(key);
|
|
21
|
+
if (session === undefined || !session.account.emailVerified)
|
|
22
|
+
return null;
|
|
23
|
+
if (session.expiresAt.getTime() <= now().getTime())
|
|
24
|
+
return null;
|
|
25
|
+
return session;
|
|
26
|
+
}
|
|
27
|
+
function handle(request) {
|
|
28
|
+
const path = new URL(request.url).pathname;
|
|
29
|
+
if (path === "/api/auth/get-session" && request.method === "GET") {
|
|
30
|
+
return Promise.resolve(Response.json(sessionFor(request.headers)));
|
|
31
|
+
}
|
|
32
|
+
if (path === "/api/auth/sign-out" && request.method === "POST") {
|
|
33
|
+
const key = tokenFrom(request.headers);
|
|
34
|
+
if (key !== undefined)
|
|
35
|
+
sessions.delete(key);
|
|
36
|
+
return Promise.resolve(Response.json({ ok: true }));
|
|
37
|
+
}
|
|
38
|
+
return Promise.resolve(Response.json({ error: "not-found" }, { status: 404 }));
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
handle,
|
|
42
|
+
readSession: (headers) => Promise.resolve(sessionFor(headers)),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=in-memory-identity.js.map
|
|
@@ -0,0 +1 @@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AK,wBAAwB,GAC9B,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,GAEjC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dads-framework/identity",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=22"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./scim": {
|
|
14
|
+
"types": "./dist/scim/index.d.ts",
|
|
15
|
+
"default": "./dist/scim/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./testing": {
|
|
18
|
+
"types": "./dist/testing/index.d.ts",
|
|
19
|
+
"default": "./dist/testing/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./impersonation": {
|
|
22
|
+
"types": "./dist/impersonation/index.d.ts",
|
|
23
|
+
"default": "./dist/impersonation/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"src/impersonation/README.md"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"prepublishOnly": "node ../../../scripts/verify-prepublish.mjs",
|
|
33
|
+
"build": "tsc -b",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"typecheck": "tsc -b --pretty false"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"vitest": "~4.1.0"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"author": "Bryton Cooper",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/brytoncooper/dads-framework.git",
|
|
45
|
+
"directory": "packages/server/identity"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Staff impersonation
|
|
2
|
+
|
|
3
|
+
Use `createImpersonation` from `@dads-framework/identity/impersonation` to authorize short-lived staff access as a specific account in a specific tenant. The original staff session supplies the actor identity on every call.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createImpersonation } from "@dads-framework/identity/impersonation";
|
|
7
|
+
|
|
8
|
+
// Application adapters implement identity, storage, tenant policy, and audit.
|
|
9
|
+
const impersonation = createImpersonation({
|
|
10
|
+
identity,
|
|
11
|
+
store: impersonationStore,
|
|
12
|
+
authorize: checkTenantImpersonationPermission,
|
|
13
|
+
writeAudit: appendImpersonationAudit,
|
|
14
|
+
lifetimeMs: 5 * 60_000,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const grant = await impersonation.start(request.headers, {
|
|
18
|
+
tenantId: routeTenantId,
|
|
19
|
+
effectiveAccountId: selectedAccountId,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// On each subsequent request, take tenantId from the route's tenant context.
|
|
23
|
+
const admitted = await impersonation.use(request.headers, {
|
|
24
|
+
grantId: suppliedGrantId,
|
|
25
|
+
tenantId: routeTenantId,
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Handle a null admission as a denial on an impersonated route. Use the declared tenant and effective account for ordinary resource authorization, and retain the staff account and grant ID in application operation logs. Attach admission to a single request and use it only inside the checked tenant. Keep identity-management and impersonation-control routes under real-actor authorization. The API returns a scope that applications apply to their own authorization and operation auditing.
|
|
30
|
+
|
|
31
|
+
The tenant policy supplies explicit staff permission and verifies target membership for both `start` and `use`. The `revoke` action checks the requesting administrator's revocation permission in the grant's tenant. `stop` is available to the original authenticated staff session, including after staff permission or grant expiry. Both commands remove the grant. Return an application error on operational failures.
|
|
32
|
+
|
|
33
|
+
The store must insert immutable grants under unique IDs, commit successful mutations and their audit records atomically, and provide strongly consistent reads across application instances. Configure a short lifetime. Use an authoritative clock across instances and periodically delete expired grants. A grant expires at the earlier of the configured lifetime and the original session's expiry. Each use requires the same valid staff session and current tenant permission. Configure an identity adapter whose server-side session lookup returns a stable, non-credential `sessionId`. The API keeps that identifier in the grant store and omits it from admission scopes and audit events. For Better Auth, spread the result of `createPostgresImpersonationStore(pool)` from `@dads-framework/identity-better-auth/impersonation-store` into the options to supply both storage and audit.
|
|
34
|
+
|
|
35
|
+
Start atomically commits its audit record with the grant. Use requires the audit writer to acknowledge a durable record before returning admission. Records carry the authenticated caller, original staff account and effective account where known. They describe gate decisions and backend errors. A concurrent revocation or expiration can produce an authorized audit record followed by a denied record. On audit failure, `ImpersonationAuditError` retains the event and original cause for application alerting. A failed atomic audit write rolls back the corresponding grant creation or removal. A failed removal must be retried.
|