@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.
Files changed (55) hide show
  1. package/README.md +20 -15
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/auth-common/SKILL.md +113 -23
  4. package/build/consts.d.ts +28 -0
  5. package/build/consts.d.ts.map +1 -1
  6. package/build/consts.js +28 -0
  7. package/build/consts.js.map +1 -1
  8. package/build/entity.d.ts +43 -0
  9. package/build/entity.d.ts.map +1 -0
  10. package/build/entity.js +68 -0
  11. package/build/entity.js.map +1 -0
  12. package/build/entrypoints.d.ts +41 -0
  13. package/build/entrypoints.d.ts.map +1 -0
  14. package/build/entrypoints.js +46 -0
  15. package/build/entrypoints.js.map +1 -0
  16. package/build/guards/basic-ed25519/service.js +1 -1
  17. package/build/guards/basic-ed25519/service.js.map +1 -1
  18. package/build/helper.d.ts +1 -0
  19. package/build/helper.d.ts.map +1 -0
  20. package/build/helper.js +2 -0
  21. package/build/helper.js.map +1 -0
  22. package/build/index.d.ts +3 -1
  23. package/build/index.d.ts.map +1 -1
  24. package/build/index.js +3 -1
  25. package/build/index.js.map +1 -1
  26. package/build/middleware.d.ts.map +1 -1
  27. package/build/middleware.js +12 -11
  28. package/build/middleware.js.map +1 -1
  29. package/build/schemas.d.ts +16 -0
  30. package/build/schemas.d.ts.map +1 -0
  31. package/build/schemas.js +10 -0
  32. package/build/schemas.js.map +1 -0
  33. package/build/types.d.ts +52 -1
  34. package/build/types.d.ts.map +1 -1
  35. package/build/utils/trusted.d.ts.map +1 -1
  36. package/build/utils/trusted.js +2 -1
  37. package/build/utils/trusted.js.map +1 -1
  38. package/package.json +12 -12
  39. package/src/consts.ts +32 -0
  40. package/src/entity.ts +82 -0
  41. package/src/entrypoints.ts +73 -0
  42. package/src/guards/basic-ed25519/service.ts +1 -1
  43. package/src/helper.ts +0 -0
  44. package/src/index.ts +3 -1
  45. package/src/middleware.ts +12 -11
  46. package/src/schemas.ts +25 -0
  47. package/src/types.ts +54 -1
  48. package/src/utils/trusted.ts +3 -2
  49. package/tests/context.ts +1 -2
  50. package/tests/dispatcher.spec.ts +15 -15
  51. package/build/modules.d.ts +0 -3
  52. package/build/modules.d.ts.map +0 -1
  53. package/build/modules.js +0 -38
  54. package/build/modules.js.map +0 -1
  55. package/src/modules.ts +0 -53
package/src/types.ts CHANGED
@@ -42,5 +42,58 @@ export interface ProfileToEntityIdRequest {
42
42
  }
43
43
 
44
44
  export interface ProfileToEntityIdResponse {
45
- entityId: string
45
+ entitySlug: string
46
+ }
47
+
48
+ /**
49
+ * An organization entity: one immutable id, one renameable slug, and the trail of slugs it used to
50
+ * answer to.
51
+ *
52
+ * `formerSlugs` is what makes a rename survivable rather than merely possible. Tokens minted before
53
+ * the rename keep arriving until they expire, and third-party systems keep quoting the old value
54
+ * indefinitely; resolving a former slug to the same entity is how both keep working without anyone
55
+ * reissuing anything.
56
+ */
57
+ export interface OrgEntityRef {
58
+ id: string
59
+ slug: string
60
+ formerSlugs?: string[]
61
+ /** Frozen identifier for systems whose names cannot be rewritten. See `ResolvedEntity.iamKey`. */
62
+ iamKey: string
63
+ }
64
+
65
+ /**
66
+ * Resolves the renameable slug on a token to the stable entity it names.
67
+ *
68
+ * Registered only by implementations that actually store organizations. Basic auth deliberately
69
+ * does not define what an entity id is — a deployment backed by an external IAM has no such record
70
+ * and registers nothing, and every consumer must therefore treat an unresolved entity as ordinary
71
+ * rather than exceptional.
72
+ */
73
+ export interface EntityResolverService extends InitializedService {
74
+ /**
75
+ * Find an entity by any name it has ever answered to: its id, its current slug, a former slug,
76
+ * or its frozen `iamKey`. Ids win over slugs, so a slug that collides with some other entity's
77
+ * id can never shadow it.
78
+ */
79
+ resolve: (value: string) => Promise<OrgEntityRef | null>
80
+ byId: (id: string) => Promise<OrgEntityRef | null>
81
+ /** Mint an unused slug. Uniqueness is settled against the store, not by entropy. */
82
+ mintSlug: () => Promise<string>
83
+ /**
84
+ * Point the entity at a new slug, retiring the old one into `formerSlugs`.
85
+ *
86
+ * This is the whole cost of a rename: nothing else in any store is touched, because nothing else
87
+ * keys on the slug.
88
+ */
89
+ rename: (id: string, slug: string) => Promise<OrgEntityRef>
90
+ /**
91
+ * Read — or, on first ask, mint and persist — a name this entity is known by in a system that
92
+ * cannot be renamed later (a namespace, a bucket prefix, a realm).
93
+ *
94
+ * Minting through the entity record rather than deriving the name on demand is what lets the
95
+ * slug move afterwards: the derivation happens once, the result is what everything addresses,
96
+ * and a later rename leaves the live resource alone.
97
+ */
98
+ mintName: (id: string, key: string, mint: (entity: OrgEntityRef) => string) => Promise<string>
46
99
  }
@@ -1,11 +1,12 @@
1
1
 
2
2
  import type { Context, Config } from './types.js'
3
3
  import type { TrustedRecord } from '../types.js'
4
- import type { Resource } from '@owlmeans/resource'
4
+ import type { Criteria, Resource } from '@owlmeans/resource'
5
5
  import { fromPubKey, makeKeyPairModel } from '@owlmeans/basic-keys'
6
6
 
7
7
  export const trust = async <C extends Config, T extends Context<C>>(context: T, resource: string, userName: string, field: string = 'name') => {
8
- const trustedUser = await context.resource<Resource<TrustedRecord>>(resource).load(userName, field)
8
+ const where: Criteria<TrustedRecord> = { [field]: userName }
9
+ const trustedUser = await context.resource<Resource<TrustedRecord>>(resource).load(where)
9
10
  if (trustedUser == null) {
10
11
  throw new SyntaxError(`Auth service trusted entity is not provided: ${userName}`)
11
12
  }
package/tests/context.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
1
+ import { AppType, makeBasicContext } from '@owlmeans/context'
2
2
  import type { BasicConfig, BasicContext } from '@owlmeans/context'
3
3
  import { makeMemoryTrustedResource, makeFixtureKeyPair } from '@owlmeans/test-auth'
4
4
  import type { TrustedRecord } from '@owlmeans/auth-common'
@@ -38,7 +38,6 @@ export const makeTrustFixture = (
38
38
  const ctx = makeBasicContext<BasicConfig>({
39
39
  ready: false,
40
40
  service: 'auth-common-tests',
41
- layer: Layer.Service,
42
41
  type: AppType.Backend,
43
42
  })
44
43
 
@@ -1,38 +1,38 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
- import { modules } from '@owlmeans/auth-common'
2
+ import { authProtocols } from '@owlmeans/auth-common'
3
3
  import { DISPATCHER, DISPATCHER_AUTHEN } from '@owlmeans/auth'
4
4
  import { DISPATCHER_PATH } from '../src/consts.js'
5
5
 
6
- // The DISPATCHER module intentionally declares service: DISPATCHER so that
7
- // urlCall() produces an absolute URL (pointing to the auth service).
6
+ // The DISPATCHER entrypoint intentionally declares service: DISPATCHER so that
7
+ // url() produces an absolute URL (pointing to the auth service).
8
8
  // The fix for the React Router 404 ("/https:/vib.owl.flat/dispatcher") lives
9
9
  // in @owlmeans/client's navigator.navigate() — when the URL is absolute it
10
10
  // does a browser redirect (globalThis.location.href) instead of React Router navigate().
11
11
 
12
- describe('@owlmeans/auth-common — DISPATCHER module declaration', () => {
13
- const dispatcher = modules.find(m => m.route.route.alias === DISPATCHER)
12
+ describe('@owlmeans/auth-common — DISPATCHER protocol declaration', () => {
13
+ const dispatcher = authProtocols.dispatcher
14
14
 
15
- test('DISPATCHER module is present in the modules array', () => {
16
- expect(dispatcher).toBeDefined()
15
+ test('DISPATCHER protocol is present in the authentication tree', () => {
16
+ expect(dispatcher.alias).toBe(DISPATCHER)
17
17
  })
18
18
 
19
19
  test('DISPATCHER route has an explicit service override (cross-service)', () => {
20
20
  // service: DISPATCHER is intentional — the dispatcher belongs to the auth service.
21
21
  // The navigator in @owlmeans/client handles the resulting absolute URL correctly.
22
- expect(dispatcher?.route.route.service).toBe(DISPATCHER)
22
+ expect(dispatcher.route.route.service).toBe(DISPATCHER)
23
23
  })
24
24
 
25
25
  test('DISPATCHER route path is DISPATCHER_PATH (/dispatcher)', () => {
26
- expect(dispatcher?.route.route.path).toBe(DISPATCHER_PATH)
26
+ expect(dispatcher.route.route.path).toBe(DISPATCHER_PATH)
27
27
  })
28
28
 
29
- test('DISPATCHER module is sticky (always registered in every app router)', () => {
30
- expect(dispatcher?.sticky).toBe(true)
29
+ test('DISPATCHER entrypoint is sticky (always registered in every app router)', () => {
30
+ expect(dispatcher.sticky).toBe(true)
31
31
  })
32
32
 
33
- test('DISPATCHER_AUTHEN backend module is distinct', () => {
34
- const dispatcherAuthen = modules.find(m => m.route.route.alias === DISPATCHER_AUTHEN)
35
- expect(dispatcherAuthen).toBeDefined()
36
- expect(dispatcherAuthen?.sticky).toBeFalsy()
33
+ test('DISPATCHER_AUTHEN backend entrypoint is distinct', () => {
34
+ const dispatcherAuthen = authProtocols.dispatcherAuthenticate
35
+ expect(dispatcherAuthen.alias).toBe(DISPATCHER_AUTHEN)
36
+ expect(dispatcherAuthen.sticky).toBeFalsy()
37
37
  })
38
38
  })
@@ -1,3 +0,0 @@
1
- export declare const modules: import("@owlmeans/entrypoint").CommonEntrypoint[];
2
- export declare const managerModules: import("@owlmeans/entrypoint").CommonEntrypoint[];
3
- //# sourceMappingURL=modules.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO,mDAuBnB,CAAA;AAED,eAAO,MAAM,cAAc,mDAW1B,CAAA"}
package/build/modules.js DELETED
@@ -1,38 +0,0 @@
1
- import { AUTHEN, AUTHEN_AUTHEN, AUTHEN_INIT, AUTHEN_RELY, AllowanceRequestSchema, AuthCredentialsSchema, AuthTokenSchema, CAUTHEN, CAUTHEN_AUTHEN, CAUTHEN_AUTHEN_DEFAULT, CAUTHEN_AUTHEN_TYPED, DISPATCHER, DISPATCHER_AUTHEN, OptionalAuthTokenSchema, CAUTHEN_FLOW_ENTER } from '@owlmeans/auth';
2
- // import { AppType } from '@owlmeans/context'
3
- import { body, filter, entrypoint, query } from '@owlmeans/entrypoint';
4
- import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route';
5
- import { DISPATCHER_PATH, WEB_API, authApi } from './consts.js';
6
- export const modules = [
7
- entrypoint(route(AUTHEN, '/authentication', backend())),
8
- entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
9
- entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
10
- entrypoint(route(AUTHEN_RELY, '/rely', socket(AUTHEN)), filter(query(OptionalAuthTokenSchema))),
11
- entrypoint(route(CAUTHEN, '/authentication', frontend())),
12
- entrypoint(route(CAUTHEN_AUTHEN, '/login', frontend(CAUTHEN))),
13
- entrypoint(route(CAUTHEN_AUTHEN_DEFAULT, '/', frontend(CAUTHEN_AUTHEN, true))),
14
- entrypoint(route(CAUTHEN_AUTHEN_TYPED, '/:type', frontend(CAUTHEN_AUTHEN))),
15
- // This is a helper route that is used by service providers to redirect to an external authentication service.
16
- entrypoint(route(CAUTHEN_FLOW_ENTER, '/', frontend())),
17
- // This is a helper route that is useb by service providres to process authentication provisioning via redirect.
18
- // Also it can be default starting point to be redirected to an external identity provider.
19
- entrypoint(route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
20
- // This module is sticky - it means it's always attach to client router.
21
- // It's required here cause every web app needs dispatcher route to authorize
22
- // rediected users.
23
- filter(query(AuthTokenSchema), { sticky: true })),
24
- // This is a helper route that representes a API endpoint of service provider that wants to authenticate
25
- // a user with OwlMeans server-auth library.
26
- entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
27
- ];
28
- export const managerModules = [
29
- entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
30
- entrypoint(route(authApi.profile.toEntityId, '/to-entity-id', backend(authApi.profile.base, RouteMethod.POST))),
31
- entrypoint(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
32
- entrypoint(route(authApi.auth.delegate, '/delegate', backend(authApi.auth.base, RouteMethod.POST))),
33
- ];
34
- // const skipModules = [DISPATCHER]
35
- // export const authBackendModules = modules.filter(
36
- // module => !skipModules.includes(module.alias) && module.route.route.type === AppType.Backend
37
- // ).map(module => module.alias)
38
- //# sourceMappingURL=modules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,qBAAqB,EAC9F,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,UAAU,EAClG,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAC/D,MAAM,gBAAgB,CAAA;AACvB,8CAA8C;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE/D,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,CAAC;IACvD,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAChH,UAAU,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,EAAE,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACzH,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,EAA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CAAC,KAAK,CACd,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,eAAe,EAC3C,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAChD,CAAC;IACF,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC5E,UAAU,CAAC,KAAK,CACd,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAClC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAC7C,CAAC;CACH,CAAA;AAED,mCAAmC;AACnC,oDAAoD;AACpD,iGAAiG;AACjG,gCAAgC"}
package/src/modules.ts DELETED
@@ -1,53 +0,0 @@
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, OptionalAuthTokenSchema, CAUTHEN_FLOW_ENTER
6
- } from '@owlmeans/auth'
7
- // import { AppType } from '@owlmeans/context'
8
- import { body, filter, entrypoint, query } from '@owlmeans/entrypoint'
9
- import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route'
10
- import { DISPATCHER_PATH, WEB_API, authApi } from './consts.js'
11
-
12
- export const modules = [
13
- entrypoint(route(AUTHEN, '/authentication', backend())),
14
- entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
15
- entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
16
- entrypoint(route(AUTHEN_RELY, '/rely', socket(AUTHEN)), filter(query(OptionalAuthTokenSchema))),
17
- entrypoint(route(CAUTHEN, '/authentication', frontend())),
18
- entrypoint(route(CAUTHEN_AUTHEN, '/login', frontend(CAUTHEN))),
19
- entrypoint(route(CAUTHEN_AUTHEN_DEFAULT, '/', frontend(CAUTHEN_AUTHEN, true))),
20
- entrypoint(route(CAUTHEN_AUTHEN_TYPED, '/:type', frontend(CAUTHEN_AUTHEN))),
21
- // This is a helper route that is used by service providers to redirect to an external authentication service.
22
- entrypoint(route(CAUTHEN_FLOW_ENTER, '/', frontend())),
23
- // This is a helper route that is useb by service providres to process authentication provisioning via redirect.
24
- // Also it can be default starting point to be redirected to an external identity provider.
25
- entrypoint(
26
- route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
27
- // This module is sticky - it means it's always attach to client router.
28
- // It's required here cause every web app needs dispatcher route to authorize
29
- // rediected users.
30
- filter(query(AuthTokenSchema), { sticky: true })
31
- ),
32
- // This is a helper route that representes a API endpoint of service provider that wants to authenticate
33
- // a user with OwlMeans server-auth library.
34
- entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
35
- ]
36
-
37
- export const managerModules = [
38
- entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
39
- entrypoint(route(
40
- authApi.profile.toEntityId, '/to-entity-id',
41
- backend(authApi.profile.base, RouteMethod.POST)
42
- )),
43
- entrypoint(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
44
- entrypoint(route(
45
- authApi.auth.delegate, '/delegate',
46
- backend(authApi.auth.base, RouteMethod.POST)
47
- )),
48
- ]
49
-
50
- // const skipModules = [DISPATCHER]
51
- // export const authBackendModules = modules.filter(
52
- // module => !skipModules.includes(module.alias) && module.route.route.type === AppType.Backend
53
- // ).map(module => module.alias)