@owlmeans/auth-common 0.1.18-rc.2 → 0.1.18-rc.21
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/README.md +20 -15
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/auth-common/SKILL.md +113 -23
- package/build/consts.d.ts +28 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +28 -0
- package/build/consts.js.map +1 -1
- package/build/entity.d.ts +43 -0
- package/build/entity.d.ts.map +1 -0
- package/build/entity.js +68 -0
- package/build/entity.js.map +1 -0
- package/build/entrypoints.d.ts +41 -0
- package/build/entrypoints.d.ts.map +1 -0
- package/build/entrypoints.js +46 -0
- package/build/entrypoints.js.map +1 -0
- package/build/guards/basic-ed25519/service.js +1 -1
- package/build/guards/basic-ed25519/service.js.map +1 -1
- package/build/helper.d.ts +1 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +2 -0
- package/build/helper.js.map +1 -0
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/middleware.d.ts.map +1 -1
- package/build/middleware.js +12 -11
- package/build/middleware.js.map +1 -1
- package/build/schemas.d.ts +16 -0
- package/build/schemas.d.ts.map +1 -0
- package/build/schemas.js +10 -0
- package/build/schemas.js.map +1 -0
- package/build/types.d.ts +52 -1
- package/build/types.d.ts.map +1 -1
- package/build/utils/trusted.d.ts.map +1 -1
- package/build/utils/trusted.js +2 -1
- package/build/utils/trusted.js.map +1 -1
- package/package.json +12 -12
- package/src/consts.ts +32 -0
- package/src/entity.ts +82 -0
- package/src/entrypoints.ts +73 -0
- package/src/guards/basic-ed25519/service.ts +1 -1
- package/src/helper.ts +0 -0
- package/src/index.ts +3 -1
- package/src/middleware.ts +12 -11
- package/src/schemas.ts +25 -0
- package/src/types.ts +54 -1
- package/src/utils/trusted.ts +3 -2
- package/tests/context.ts +1 -2
- package/tests/dispatcher.spec.ts +15 -15
- package/build/modules.d.ts +0 -3
- package/build/modules.d.ts.map +0 -1
- package/build/modules.js +0 -38
- package/build/modules.js.map +0 -1
- package/src/modules.ts +0 -53
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":""}
|
package/build/helper.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":""}
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type * from './types.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './schemas.js';
|
|
3
|
+
export * from './entrypoints.js';
|
|
3
4
|
export * from './consts.js';
|
|
5
|
+
export * from './entity.js';
|
|
4
6
|
export * from './middleware.js';
|
|
5
7
|
export * from './guards/index.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './schemas.js';
|
|
2
|
+
export * from './entrypoints.js';
|
|
2
3
|
export * from './consts.js';
|
|
4
|
+
export * from './entity.js';
|
|
3
5
|
export * from './middleware.js';
|
|
4
6
|
export * from './guards/index.js';
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAOnD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAOnD,eAAO,MAAM,cAAc,EAAE,UAuC5B,CAAA"}
|
package/build/middleware.js
CHANGED
|
@@ -6,22 +6,23 @@ export const authMiddleware = {
|
|
|
6
6
|
stage: MiddlewareStage.Loading,
|
|
7
7
|
apply: async (context) => {
|
|
8
8
|
context.entrypoints().forEach(module => {
|
|
9
|
-
if (module.route.route.type === AppType.Backend && module.
|
|
10
|
-
|
|
11
|
-
if (guards.length > 0) {
|
|
9
|
+
if (module.route.route.type === AppType.Backend && module.invoke != null) {
|
|
10
|
+
if (module.getGuards().length > 0) {
|
|
12
11
|
if (module._auth_common_middleware_applied === true) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
14
|
module._auth_common_middleware_applied = true;
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
// Wrapping `invoke` covers `call` too: `call` reads `invoke` off the entrypoint at the
|
|
16
|
+
// moment it runs, so both verbs carry the authentication header.
|
|
17
|
+
const invoke = module.invoke;
|
|
18
|
+
module.invoke = (async (req) => {
|
|
19
19
|
// @TODO Actually we may use multiple authentication headers with the same name
|
|
20
20
|
// As I learnt its not always the case
|
|
21
|
-
|
|
21
|
+
// Asked per call, not captured: an ancestor may have gained a guard since the
|
|
22
|
+
// middleware wrapped this entrypoint.
|
|
23
|
+
const [token] = (await Promise.all(module.getGuards().map(guard => context.service(guard).authenticated(req)))).filter(token => token != null).reverse();
|
|
22
24
|
if (token != null) {
|
|
23
|
-
|
|
24
|
-
const _req = req ?? provideRequest(module.getAlias(), module.getPath());
|
|
25
|
+
const _req = req ?? provideRequest(module.alias, module.path());
|
|
25
26
|
const headers = (_req.headers ?? {});
|
|
26
27
|
if (headers[AUTH_HEADER] == null) {
|
|
27
28
|
headers[AUTH_HEADER] = token;
|
|
@@ -29,8 +30,8 @@ export const authMiddleware = {
|
|
|
29
30
|
req = _req;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
-
};
|
|
33
|
+
return invoke(req);
|
|
34
|
+
});
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
});
|
package/build/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,M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optional: the window must render something sensible when opened by hand, or by an
|
|
6
|
+
* older build that knew none of these parameters. `next` carries the address to run once the
|
|
7
|
+
* window is one level up, so the flow parameters the opener's URL held are forwarded rather than
|
|
8
|
+
* silently dropped.
|
|
9
|
+
*/
|
|
10
|
+
export interface SurrogateQuery {
|
|
11
|
+
intent?: string;
|
|
12
|
+
next?: string;
|
|
13
|
+
method?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SurrogateQuerySchema: JSONSchemaType<SurrogateQuery>;
|
|
16
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEzC;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,cAAc,CAQ/D,CAAA"}
|
package/build/schemas.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const SurrogateQuerySchema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
intent: { type: 'string', maxLength: 32, nullable: true },
|
|
5
|
+
next: { type: 'string', maxLength: 2048, nullable: true },
|
|
6
|
+
method: { type: 'string', maxLength: 128, nullable: true },
|
|
7
|
+
},
|
|
8
|
+
additionalProperties: true,
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,oBAAoB,GAAmC;IAClE,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzD,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE;KAC3D;IACD,oBAAoB,EAAE,IAAI;CAC3B,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -29,6 +29,57 @@ export interface ProfileToEntityIdRequest {
|
|
|
29
29
|
profileId: string;
|
|
30
30
|
}
|
|
31
31
|
export interface ProfileToEntityIdResponse {
|
|
32
|
-
|
|
32
|
+
entitySlug: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An organization entity: one immutable id, one renameable slug, and the trail of slugs it used to
|
|
36
|
+
* answer to.
|
|
37
|
+
*
|
|
38
|
+
* `formerSlugs` is what makes a rename survivable rather than merely possible. Tokens minted before
|
|
39
|
+
* the rename keep arriving until they expire, and third-party systems keep quoting the old value
|
|
40
|
+
* indefinitely; resolving a former slug to the same entity is how both keep working without anyone
|
|
41
|
+
* reissuing anything.
|
|
42
|
+
*/
|
|
43
|
+
export interface OrgEntityRef {
|
|
44
|
+
id: string;
|
|
45
|
+
slug: string;
|
|
46
|
+
formerSlugs?: string[];
|
|
47
|
+
/** Frozen identifier for systems whose names cannot be rewritten. See `ResolvedEntity.iamKey`. */
|
|
48
|
+
iamKey: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the renameable slug on a token to the stable entity it names.
|
|
52
|
+
*
|
|
53
|
+
* Registered only by implementations that actually store organizations. Basic auth deliberately
|
|
54
|
+
* does not define what an entity id is — a deployment backed by an external IAM has no such record
|
|
55
|
+
* and registers nothing, and every consumer must therefore treat an unresolved entity as ordinary
|
|
56
|
+
* rather than exceptional.
|
|
57
|
+
*/
|
|
58
|
+
export interface EntityResolverService extends InitializedService {
|
|
59
|
+
/**
|
|
60
|
+
* Find an entity by any name it has ever answered to: its id, its current slug, a former slug,
|
|
61
|
+
* or its frozen `iamKey`. Ids win over slugs, so a slug that collides with some other entity's
|
|
62
|
+
* id can never shadow it.
|
|
63
|
+
*/
|
|
64
|
+
resolve: (value: string) => Promise<OrgEntityRef | null>;
|
|
65
|
+
byId: (id: string) => Promise<OrgEntityRef | null>;
|
|
66
|
+
/** Mint an unused slug. Uniqueness is settled against the store, not by entropy. */
|
|
67
|
+
mintSlug: () => Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Point the entity at a new slug, retiring the old one into `formerSlugs`.
|
|
70
|
+
*
|
|
71
|
+
* This is the whole cost of a rename: nothing else in any store is touched, because nothing else
|
|
72
|
+
* keys on the slug.
|
|
73
|
+
*/
|
|
74
|
+
rename: (id: string, slug: string) => Promise<OrgEntityRef>;
|
|
75
|
+
/**
|
|
76
|
+
* Read — or, on first ask, mint and persist — a name this entity is known by in a system that
|
|
77
|
+
* cannot be renamed later (a namespace, a bucket prefix, a realm).
|
|
78
|
+
*
|
|
79
|
+
* Minting through the entity record rather than deriving the name on demand is what lets the
|
|
80
|
+
* slug move afterwards: the derivation happens once, the result is what everything addresses,
|
|
81
|
+
* and a later rename leaves the live resource alone.
|
|
82
|
+
*/
|
|
83
|
+
mintName: (id: string, key: string, mint: (entity: OrgEntityRef) => string) => Promise<string>;
|
|
33
84
|
}
|
|
34
85
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB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AAO,CAAC,MAAM,CAAC,CAAA;CAC/F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trusted.d.ts","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIhD,eAAO,MAAM,KAAK,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,MAAM,YAAY,MAAM,UAAS,MAAM;;;
|
|
1
|
+
{"version":3,"file":"trusted.d.ts","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIhD,eAAO,MAAM,KAAK,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,MAAM,YAAY,MAAM,UAAS,MAAM;;;EAWhI,CAAA"}
|
package/build/utils/trusted.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fromPubKey, makeKeyPairModel } from '@owlmeans/basic-keys';
|
|
2
2
|
export const trust = async (context, resource, userName, field = 'name') => {
|
|
3
|
-
const
|
|
3
|
+
const where = { [field]: userName };
|
|
4
|
+
const trustedUser = await context.resource(resource).load(where);
|
|
4
5
|
if (trustedUser == null) {
|
|
5
6
|
throw new SyntaxError(`Auth service trusted entity is not provided: ${userName}`);
|
|
6
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trusted.js","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEnE,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAA0C,OAAU,EAAE,QAAgB,EAAE,QAAgB,EAAE,KAAK,GAAW,MAAM,EAAE,EAAE;IAC5I,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,QAAQ,CAA0B,QAAQ,CAAC,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"trusted.js","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEnE,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAA0C,OAAU,EAAE,QAAgB,EAAE,QAAgB,EAAE,KAAK,GAAW,MAAM,EAAE,EAAE;IAC5I,MAAM,KAAK,GAA4B,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAA;IAC5D,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,QAAQ,CAA0B,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzF,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,IAAI,WAAW,CAAC,gDAAgD,QAAQ,EAAE,CAAC,CAAA;IACnF,CAAC;IAED,4EAA4E;IAC5E,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,UAAW,CAAC,CAAA;IAEvH,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;AAC5C,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/auth-common",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
33
|
-
"@owlmeans/auth-common": "^0.1.18-rc.
|
|
34
|
-
"@owlmeans/basic-ids": "^0.1.18-rc.
|
|
35
|
-
"@owlmeans/basic-keys": "^0.1.18-rc.
|
|
36
|
-
"@owlmeans/client-entrypoint": "^0.1.18-rc.
|
|
37
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
38
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
39
|
-
"@owlmeans/resource": "^0.1.18-rc.
|
|
40
|
-
"@owlmeans/route": "^0.1.18-rc.
|
|
32
|
+
"@owlmeans/auth": "^0.1.18-rc.17",
|
|
33
|
+
"@owlmeans/auth-common": "^0.1.18-rc.21",
|
|
34
|
+
"@owlmeans/basic-ids": "^0.1.18-rc.17",
|
|
35
|
+
"@owlmeans/basic-keys": "^0.1.18-rc.20",
|
|
36
|
+
"@owlmeans/client-entrypoint": "^0.1.18-rc.21",
|
|
37
|
+
"@owlmeans/context": "^0.1.18-rc.16",
|
|
38
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.19",
|
|
39
|
+
"@owlmeans/resource": "^0.1.18-rc.17",
|
|
40
|
+
"@owlmeans/route": "^0.1.18-rc.17"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@owlmeans/dep-config": "workspace:*",
|
|
44
|
-
"@owlmeans/test-auth": "^0.1.18-rc.
|
|
45
|
-
"@types/bun": "^1.
|
|
44
|
+
"@owlmeans/test-auth": "^0.1.18-rc.21",
|
|
45
|
+
"@types/bun": "^1.4.0",
|
|
46
46
|
"nodemon": "^3.1.14",
|
|
47
47
|
"typescript": "^7.0.2"
|
|
48
48
|
},
|
package/src/consts.ts
CHANGED
|
@@ -8,6 +8,15 @@ export const RELY_ACTION_TIMEOUT = 600
|
|
|
8
8
|
|
|
9
9
|
export const DISPATCHER_PATH = '/dispatcher'
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Where the surrogate login window runs.
|
|
13
|
+
*
|
|
14
|
+
* Reserved exactly like {@link DISPATCHER_PATH}: an application must not declare a route of its
|
|
15
|
+
* own here, and a code generator must not produce one. It is user-visible — it is what the popup's
|
|
16
|
+
* address bar shows.
|
|
17
|
+
*/
|
|
18
|
+
export const SURROGATE_PATH = '/surrogate'
|
|
19
|
+
|
|
11
20
|
export const DEF_AUTH_SRV = 'auth'
|
|
12
21
|
|
|
13
22
|
export const DEFAULT_GUARD = DEF_AUTH_SRV
|
|
@@ -16,6 +25,19 @@ export const TOKEN_UPDATE = 'auth-token-refresh'
|
|
|
16
25
|
|
|
17
26
|
export const WEB_API = 'web-auth-api'
|
|
18
27
|
|
|
28
|
+
/** Service alias of the organization-entity resolver, when an implementation registers one. */
|
|
29
|
+
export const ENTITY_RESOLVER = 'entity-resolver'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What an organization slug may look like: a DNS label, lowercase.
|
|
33
|
+
*
|
|
34
|
+
* The constraint is not cosmetic. The same slug is used to compose hostnames, Kubernetes object
|
|
35
|
+
* names and OIDC client ids, so anything that would need sanitising before it could address one of
|
|
36
|
+
* those is rejected at the point it is chosen instead — a slug that survives this pattern passes
|
|
37
|
+
* through every downstream name unchanged.
|
|
38
|
+
*/
|
|
39
|
+
export const ENTITY_SLUG_PATTERN = /^[a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?$/
|
|
40
|
+
|
|
19
41
|
export const authApi = {
|
|
20
42
|
profile: {
|
|
21
43
|
base: 'api:profile',
|
|
@@ -36,3 +58,13 @@ export const authApi = {
|
|
|
36
58
|
},
|
|
37
59
|
}
|
|
38
60
|
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The request header an authenticated call carries, re-exported for the packages that only depend
|
|
64
|
+
* on this half of the vocabulary.
|
|
65
|
+
*
|
|
66
|
+
* One spelling, one home: it is declared by `@owlmeans/auth` and named here so a client-side
|
|
67
|
+
* package does not have to take a dependency on the whole auth package to recognise its own
|
|
68
|
+
* bearer on a request it is about to send.
|
|
69
|
+
*/
|
|
70
|
+
export { AUTH_HEADER } from '@owlmeans/auth'
|
package/src/entity.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AbstractRequest, ResolvedEntity } from '@owlmeans/entrypoint'
|
|
2
|
+
import type { BasicContext } from '@owlmeans/context'
|
|
3
|
+
import { AuthenFailed, AuthorizationError, entitySlugOf } from '@owlmeans/auth'
|
|
4
|
+
import type { EntityResolverService } from './types.js'
|
|
5
|
+
import { ENTITY_RESOLVER } from './consts.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The value a handler should store and query organization-scoped records by.
|
|
9
|
+
*
|
|
10
|
+
* Prefers the entity's stable id, which is the whole point of resolving one: records keyed by it
|
|
11
|
+
* survive a rename untouched. Falls back to the slug on the token for deployments that register no
|
|
12
|
+
* resolver — there the slug IS the only identifier the system has, and refusing to serve them
|
|
13
|
+
* would break every installation backed by an external IAM.
|
|
14
|
+
*
|
|
15
|
+
* Never use this to compose a user-facing name (a hostname, a display label). Those want the
|
|
16
|
+
* current slug, `req.entity?.slug`, precisely because it can change.
|
|
17
|
+
*/
|
|
18
|
+
export const entityKeyOf = (req: AbstractRequest): string | undefined =>
|
|
19
|
+
req.entity?.id ?? entitySlugOf(req.auth)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `entityKeyOf` for handlers that cannot proceed without an organization.
|
|
23
|
+
*
|
|
24
|
+
* @throws {AuthorizationError} when the request carries no organization at all.
|
|
25
|
+
*/
|
|
26
|
+
export const requireEntityKey = (req: AbstractRequest): string => {
|
|
27
|
+
const key = entityKeyOf(req)
|
|
28
|
+
if (key == null || key === '') {
|
|
29
|
+
throw new AuthorizationError()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return key
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The full resolved entity, for handlers that need the slug or the frozen key as well as the id.
|
|
37
|
+
*
|
|
38
|
+
* @throws {AuthorizationError} when no resolver is registered or the entity did not resolve.
|
|
39
|
+
*/
|
|
40
|
+
export const requireEntity = (req: AbstractRequest): ResolvedEntity => {
|
|
41
|
+
if (req.entity == null) {
|
|
42
|
+
throw new AuthorizationError()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return req.entity
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the organization a just-authenticated request acts for, and attach it.
|
|
50
|
+
*
|
|
51
|
+
* Called wherever authentication is ESTABLISHED — the HTTP boundary, and any socket that
|
|
52
|
+
* authenticates on its own once the connection is already open. Both need it for the same reason:
|
|
53
|
+
* the token names the organization by a slug that can move, while everything downstream keys on
|
|
54
|
+
* the record. A path that authenticates without calling this leaves `request.entity` empty, and
|
|
55
|
+
* its handlers quietly fall back to comparing a slug against stored ids — which surfaces as "this
|
|
56
|
+
* project does not exist" rather than as a missing resolution, and costs an afternoon to find.
|
|
57
|
+
*
|
|
58
|
+
* A no-op when no resolver is registered: such a deployment has no organization store, and the
|
|
59
|
+
* slug is the only identifier it has.
|
|
60
|
+
*
|
|
61
|
+
* @throws {AuthenFailed} when the token names an organization that cannot be resolved.
|
|
62
|
+
*/
|
|
63
|
+
export const attachEntity = async (
|
|
64
|
+
context: BasicContext<any>, request: AbstractRequest
|
|
65
|
+
): Promise<ResolvedEntity | undefined> => {
|
|
66
|
+
const slug = entitySlugOf(request.auth)
|
|
67
|
+
if (slug == null || !context.hasService(ENTITY_RESOLVER)) {
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const entity = await context.service<EntityResolverService>(ENTITY_RESOLVER).resolve(slug)
|
|
72
|
+
if (entity == null) {
|
|
73
|
+
throw new AuthenFailed('entity')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Canonicalize: a request that arrived under a retired slug continues under the current one, so
|
|
77
|
+
// nothing echoing the value back can re-publish a name the organization has dropped.
|
|
78
|
+
request.auth!.entitySlug = entity.slug
|
|
79
|
+
request.entity = entity
|
|
80
|
+
|
|
81
|
+
return entity
|
|
82
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
AUTHEN, AUTHEN_AUTHEN, AUTHEN_INIT, AUTHEN_RELY, AllowanceRequestSchema, AuthCredentialsSchema,
|
|
4
|
+
AuthTokenSchema, CAUTHEN, CAUTHEN_AUTHEN, CAUTHEN_AUTHEN_DEFAULT, CAUTHEN_AUTHEN_TYPED, DISPATCHER,
|
|
5
|
+
DISPATCHER_AUTHEN, DISPATCHER_SURROGATE, OptionalAuthTokenSchema, CAUTHEN_FLOW_ENTER
|
|
6
|
+
} from '@owlmeans/auth'
|
|
7
|
+
import type { AllowanceRequest, AllowanceResponse, AuthCredentials, AuthToken } from '@owlmeans/auth'
|
|
8
|
+
// import { AppType } from '@owlmeans/context'
|
|
9
|
+
import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint'
|
|
10
|
+
import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route'
|
|
11
|
+
import { DISPATCHER_PATH, SURROGATE_PATH, WEB_API, authApi } from './consts.js'
|
|
12
|
+
import { SurrogateQuerySchema } from './schemas.js'
|
|
13
|
+
import type { SurrogateQuery } from './schemas.js'
|
|
14
|
+
|
|
15
|
+
/** Shared authentication protocols, bound independently by server and browser packages. */
|
|
16
|
+
export const authProtocols = {
|
|
17
|
+
authen: openProtocol(route(AUTHEN, '/authentication', backend())),
|
|
18
|
+
init: protocol(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)),
|
|
19
|
+
contract.request({ body: typed<AllowanceRequest>(AllowanceRequestSchema) }, typed<AllowanceResponse>())),
|
|
20
|
+
authenticate: protocol(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)),
|
|
21
|
+
contract.request({ body: typed<AuthCredentials>(AuthCredentialsSchema) }, typed<AuthToken>())),
|
|
22
|
+
rely: protocol(route(AUTHEN_RELY, '/rely', socket(AUTHEN)),
|
|
23
|
+
contract.request({ query: typed<Partial<AuthToken>>(OptionalAuthTokenSchema) }, typed<undefined>())),
|
|
24
|
+
client: openProtocol(route(CAUTHEN, '/authentication', frontend())),
|
|
25
|
+
login: openProtocol(route(CAUTHEN_AUTHEN, '/login', frontend(CAUTHEN))),
|
|
26
|
+
loginDefault: openProtocol(route(CAUTHEN_AUTHEN_DEFAULT, '/', frontend(CAUTHEN_AUTHEN, true))),
|
|
27
|
+
loginTyped: openProtocol(route(CAUTHEN_AUTHEN_TYPED, '/:type', frontend(CAUTHEN_AUTHEN))),
|
|
28
|
+
flowEnter: openProtocol(route(CAUTHEN_FLOW_ENTER, '/', frontend())),
|
|
29
|
+
dispatcher: protocol(
|
|
30
|
+
route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
|
|
31
|
+
contract.request({ query: typed<AuthToken>(AuthTokenSchema) }, typed()),
|
|
32
|
+
{ sticky: true },
|
|
33
|
+
),
|
|
34
|
+
// The login window an embedded application opens one level up.
|
|
35
|
+
//
|
|
36
|
+
// Top level and with no parent, so it renders outside every application layout — a popup must
|
|
37
|
+
// never show the application, with its navigation, inside itself. Sticky for the same reason the
|
|
38
|
+
// dispatcher is: it must attach to the client router regardless of service selection. It carries
|
|
39
|
+
// no `service`, unlike the dispatcher, because nothing server-side ever addresses it — the
|
|
40
|
+
// provider's callback goes to the dispatcher. And no guard: it is where a signed-out user lands.
|
|
41
|
+
surrogate: protocol(
|
|
42
|
+
route(DISPATCHER_SURROGATE, SURROGATE_PATH, frontend()),
|
|
43
|
+
contract.request({ query: typed<SurrogateQuery>(SurrogateQuerySchema) }, typed()),
|
|
44
|
+
{ sticky: true },
|
|
45
|
+
),
|
|
46
|
+
// This is a helper route that representes a API endpoint of service provider that wants to authenticate
|
|
47
|
+
// a user with OwlMeans server-auth library.
|
|
48
|
+
dispatcherAuthenticate: protocol(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)),
|
|
49
|
+
contract.request({ body: typed<AuthToken>(AuthTokenSchema) }, typed<AuthToken>())),
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Shared manager authentication protocols. */
|
|
53
|
+
export const managerProtocols = {
|
|
54
|
+
profile: {
|
|
55
|
+
base: openProtocol(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
|
|
56
|
+
toEntityId: openProtocol(route(
|
|
57
|
+
authApi.profile.toEntityId, '/to-entity-id',
|
|
58
|
+
backend(authApi.profile.base, RouteMethod.POST)
|
|
59
|
+
)),
|
|
60
|
+
},
|
|
61
|
+
auth: {
|
|
62
|
+
base: openProtocol(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
|
|
63
|
+
delegate: openProtocol(route(
|
|
64
|
+
authApi.auth.delegate, '/delegate',
|
|
65
|
+
backend(authApi.auth.base, RouteMethod.POST)
|
|
66
|
+
)),
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// const skipEntrypoints = [DISPATCHER]
|
|
71
|
+
// export const authBackendEntrypoints = entrypoints.filter(
|
|
72
|
+
// module => !skipEntrypoints.includes(module.alias) && module.route.route.type === AppType.Backend
|
|
73
|
+
// ).map(module => module.alias)
|
|
@@ -120,7 +120,7 @@ export const makeBasicEd25519Guard = (resource: string, opts?: BasicEd25519Guard
|
|
|
120
120
|
token: authorization,
|
|
121
121
|
userId: trusted.user.id,
|
|
122
122
|
profileId: trusted.user.id,
|
|
123
|
-
|
|
123
|
+
entitySlug: trusted.user.entitySlug,
|
|
124
124
|
scopes: trusted.user.name != null ? [trusted.user.name] : [],
|
|
125
125
|
type: AuthroizationType.Ed25519BasicSignature,
|
|
126
126
|
source: context.cfg.service,
|
package/src/helper.ts
ADDED
|
File without changes
|
package/src/index.ts
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -10,24 +10,25 @@ export const authMiddleware: Middleware = {
|
|
|
10
10
|
stage: MiddlewareStage.Loading,
|
|
11
11
|
apply: async context => {
|
|
12
12
|
context.entrypoints<Perked>().forEach(module => {
|
|
13
|
-
if (module.route.route.type === AppType.Backend && module.
|
|
14
|
-
|
|
15
|
-
if (guards.length > 0) {
|
|
13
|
+
if (module.route.route.type === AppType.Backend && module.invoke != null) {
|
|
14
|
+
if (module.getGuards().length > 0) {
|
|
16
15
|
if (module._auth_common_middleware_applied === true) {
|
|
17
16
|
return
|
|
18
17
|
}
|
|
19
18
|
module._auth_common_middleware_applied = true
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
// Wrapping `invoke` covers `call` too: `call` reads `invoke` off the entrypoint at the
|
|
20
|
+
// moment it runs, so both verbs carry the authentication header.
|
|
21
|
+
const invoke = module.invoke
|
|
22
|
+
module.invoke = (async req => {
|
|
23
23
|
// @TODO Actually we may use multiple authentication headers with the same name
|
|
24
24
|
// As I learnt its not always the case
|
|
25
|
-
|
|
25
|
+
// Asked per call, not captured: an ancestor may have gained a guard since the
|
|
26
|
+
// middleware wrapped this entrypoint.
|
|
27
|
+
const [token] = (await Promise.all(module.getGuards().map(
|
|
26
28
|
guard => context.service<GuardService>(guard).authenticated(req)
|
|
27
29
|
))).filter(token => token != null).reverse()
|
|
28
30
|
if (token != null) {
|
|
29
|
-
|
|
30
|
-
const _req: Partial<AbstractRequest> = req ?? provideRequest(module.getAlias(), module.getPath())
|
|
31
|
+
const _req: Partial<AbstractRequest> = req ?? provideRequest(module.alias, module.path())
|
|
31
32
|
const headers = (_req.headers ?? {}) as Record<string, string | undefined>
|
|
32
33
|
if (headers[AUTH_HEADER] == null) {
|
|
33
34
|
headers[AUTH_HEADER] = token
|
|
@@ -36,8 +37,8 @@ export const authMiddleware: Middleware = {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
return
|
|
40
|
-
}
|
|
40
|
+
return invoke(req)
|
|
41
|
+
}) as typeof module.invoke
|
|
41
42
|
|
|
42
43
|
}
|
|
43
44
|
}
|
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JSONSchemaType } from 'ajv'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What the surrogate login window is told about why it was opened.
|
|
5
|
+
*
|
|
6
|
+
* Every field is optional: the window must render something sensible when opened by hand, or by an
|
|
7
|
+
* older build that knew none of these parameters. `next` carries the address to run once the
|
|
8
|
+
* window is one level up, so the flow parameters the opener's URL held are forwarded rather than
|
|
9
|
+
* silently dropped.
|
|
10
|
+
*/
|
|
11
|
+
export interface SurrogateQuery {
|
|
12
|
+
intent?: string
|
|
13
|
+
next?: string
|
|
14
|
+
method?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const SurrogateQuerySchema: JSONSchemaType<SurrogateQuery> = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
intent: { type: 'string', maxLength: 32, nullable: true },
|
|
21
|
+
next: { type: 'string', maxLength: 2048, nullable: true },
|
|
22
|
+
method: { type: 'string', maxLength: 128, nullable: true },
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: true,
|
|
25
|
+
}
|