@owlmeans/auth-common 0.1.18-rc.8 → 0.1.18

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 (84) hide show
  1. package/README.md +31 -17
  2. package/agent-meta/manifest.json +3 -3
  3. package/agent-meta/skills/auth-common/SKILL.md +124 -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/types.d.ts +52 -0
  9. package/build/entity/types.d.ts.map +1 -0
  10. package/build/entity/types.js +2 -0
  11. package/build/entity/types.js.map +1 -0
  12. package/build/entity.d.ts +11 -0
  13. package/build/entity.d.ts.map +1 -0
  14. package/build/entity.js +47 -0
  15. package/build/entity.js.map +1 -0
  16. package/build/entrypoints.d.ts +41 -0
  17. package/build/entrypoints.d.ts.map +1 -0
  18. package/build/entrypoints.js +46 -0
  19. package/build/entrypoints.js.map +1 -0
  20. package/build/guards/basic-ed25519/consts.local.d.ts +3 -0
  21. package/build/guards/basic-ed25519/consts.local.d.ts.map +1 -0
  22. package/build/guards/basic-ed25519/consts.local.js +4 -0
  23. package/build/guards/basic-ed25519/consts.local.js.map +1 -0
  24. package/build/guards/basic-ed25519/index.d.ts +1 -0
  25. package/build/guards/basic-ed25519/index.d.ts.map +1 -1
  26. package/build/guards/basic-ed25519/index.js +1 -0
  27. package/build/guards/basic-ed25519/index.js.map +1 -1
  28. package/build/guards/basic-ed25519/replay.d.ts +14 -0
  29. package/build/guards/basic-ed25519/replay.d.ts.map +1 -0
  30. package/build/guards/basic-ed25519/replay.js +49 -0
  31. package/build/guards/basic-ed25519/replay.js.map +1 -0
  32. package/build/guards/basic-ed25519/service.d.ts +0 -5
  33. package/build/guards/basic-ed25519/service.d.ts.map +1 -1
  34. package/build/guards/basic-ed25519/service.js +35 -21
  35. package/build/guards/basic-ed25519/service.js.map +1 -1
  36. package/build/guards/basic-ed25519/types.d.ts +16 -0
  37. package/build/guards/basic-ed25519/types.d.ts.map +1 -1
  38. package/build/helper.d.ts +1 -0
  39. package/build/helper.d.ts.map +1 -0
  40. package/build/helper.js +2 -0
  41. package/build/helper.js.map +1 -0
  42. package/build/index.d.ts +4 -1
  43. package/build/index.d.ts.map +1 -1
  44. package/build/index.js +3 -1
  45. package/build/index.js.map +1 -1
  46. package/build/middleware.d.ts +1 -1
  47. package/build/middleware.d.ts.map +1 -1
  48. package/build/middleware.js +13 -12
  49. package/build/middleware.js.map +1 -1
  50. package/build/schemas.d.ts +4 -0
  51. package/build/schemas.d.ts.map +1 -0
  52. package/build/schemas.js +10 -0
  53. package/build/schemas.js.map +1 -0
  54. package/build/types.d.ts +65 -1
  55. package/build/types.d.ts.map +1 -1
  56. package/build/types.local.d.ts +5 -0
  57. package/build/types.local.d.ts.map +1 -0
  58. package/build/types.local.js +2 -0
  59. package/build/types.local.js.map +1 -0
  60. package/build/utils/trusted.d.ts.map +1 -1
  61. package/build/utils/trusted.js +4 -3
  62. package/build/utils/trusted.js.map +1 -1
  63. package/package.json +13 -13
  64. package/src/consts.ts +32 -0
  65. package/src/entity/types.ts +52 -0
  66. package/src/entity.ts +67 -0
  67. package/src/entrypoints.ts +68 -0
  68. package/src/guards/basic-ed25519/consts.local.ts +4 -0
  69. package/src/guards/basic-ed25519/index.ts +1 -0
  70. package/src/guards/basic-ed25519/replay.ts +55 -0
  71. package/src/guards/basic-ed25519/service.ts +45 -26
  72. package/src/guards/basic-ed25519/types.ts +17 -0
  73. package/src/helper.ts +0 -0
  74. package/src/index.ts +4 -1
  75. package/src/middleware.ts +15 -18
  76. package/src/schemas.ts +12 -0
  77. package/src/types.local.ts +5 -0
  78. package/src/types.ts +68 -1
  79. package/src/utils/trusted.ts +5 -4
  80. package/tests/basic-ed25519.spec.ts +99 -0
  81. package/tests/context.ts +1 -2
  82. package/tests/dispatcher.spec.ts +15 -15
  83. package/tests/entity.spec.ts +112 -0
  84. package/src/modules.ts +0 -53
package/src/types.ts CHANGED
@@ -42,5 +42,72 @@ 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>
99
+ }
100
+
101
+ /**
102
+ * What the surrogate login window is told about why it was opened.
103
+ *
104
+ * Every field is optional: the window must render something sensible when opened by hand, or by an
105
+ * older build that knew none of these parameters. `next` carries the address to run once the
106
+ * window is one level up, so the flow parameters the opener's URL held are forwarded rather than
107
+ * silently dropped.
108
+ */
109
+ export interface SurrogateQuery {
110
+ intent?: string
111
+ next?: string
112
+ method?: string
46
113
  }
@@ -1,17 +1,18 @@
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'
5
- import { fromPubKey, makeKeyPairModel } from '@owlmeans/basic-keys'
4
+ import type { Criteria, Resource } from '@owlmeans/resource'
5
+ import { keyHelper, 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
  }
12
13
 
13
14
  // @TODO credential can really be undefined - we need to process it properly
14
- const keyPair = trustedUser.secret != null ? makeKeyPairModel(trustedUser.secret) : fromPubKey(trustedUser.credential!)
15
+ const keyPair = trustedUser.secret != null ? makeKeyPairModel(trustedUser.secret) : keyHelper.fromPubKey(trustedUser.credential!)
15
16
 
16
17
  return { user: trustedUser, key: keyPair }
17
18
  }
@@ -0,0 +1,99 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { AuthenPayloadError, AuthroizationType } from '@owlmeans/auth'
3
+ import {
4
+ BED255_NONCE_HEADER, BED255_SIG_TTL, BED255_TIME_HEADER, makeBasicEd25519Guard,
5
+ makeResourceSignedRequestReplayStore
6
+ } from '@owlmeans/auth-common'
7
+ import type { BasicEd25519Guard, SignedRequestReplayResource } from '@owlmeans/auth-common'
8
+ import type { AbstractRequest, AbstractResponse } from '@owlmeans/entrypoint'
9
+ import type { Auth } from '@owlmeans/auth'
10
+ import { RecordExists } from '@owlmeans/resource'
11
+ import { makeTrustFixture, TRUSTED_ALIAS } from './context.js'
12
+
13
+ const timeKey = BED255_TIME_HEADER.toLowerCase()
14
+ const nonceKey = BED255_NONCE_HEADER.toLowerCase()
15
+
16
+ const request = async (timestamp: string, nonce: string) => {
17
+ const fixture = makeTrustFixture({ withSecret: true, name: 'auth-common-tests' })
18
+ const body = { action: 'publish' }
19
+ const signature = await fixture.authKey.sign({
20
+ body,
21
+ headers: { [timeKey]: timestamp, [nonceKey]: nonce }
22
+ })
23
+ const req = {
24
+ alias: 'signed', body, headers: {
25
+ [timeKey]: timestamp,
26
+ [nonceKey]: nonce,
27
+ authorization: `${AuthroizationType.Ed25519BasicSignature.toUpperCase()} `
28
+ + `Credential=${fixture.authRecord.id} Signature=${signature}`,
29
+ }, params: {}, query: {}, path: '/signed'
30
+ } satisfies AbstractRequest
31
+ const guard = makeBasicEd25519Guard(TRUSTED_ALIAS)
32
+ fixture.ctx.registerService(guard)
33
+
34
+ return { fixture, guard, req }
35
+ }
36
+
37
+ const handle = async (
38
+ guard: BasicEd25519Guard, req: AbstractRequest
39
+ ): Promise<Auth | undefined> => {
40
+ let value: Auth | undefined
41
+ const response: AbstractResponse<Auth> = {
42
+ resolve: resolved => { value = resolved },
43
+ reject: error => { throw error }
44
+ }
45
+ await guard.handle(req, response)
46
+ return value
47
+ }
48
+
49
+ describe('@owlmeans/auth-common — signed request freshness and replay protection', () => {
50
+ test('accepts a canonical current timestamp once and rejects the replay by default', async () => {
51
+ const signed = await request(new Date().toISOString(), 'one-use-nonce')
52
+
53
+ expect((await handle(signed.guard, signed.req))?.userId).toBe(signed.fixture.authRecord.id)
54
+ await expect(handle(signed.guard, signed.req)).rejects.toBeInstanceOf(AuthenPayloadError)
55
+ })
56
+
57
+ test('rejects parseable but non-canonical timestamps', async () => {
58
+ const signed = await request(new Date().toUTCString(), 'non-canonical')
59
+
60
+ await expect(handle(signed.guard, signed.req)).rejects.toBeInstanceOf(AuthenPayloadError)
61
+ })
62
+
63
+ test('rejects timestamps outside the symmetric 60-second window', async () => {
64
+ const past = await request(new Date(Date.now() - BED255_SIG_TTL - 1_000).toISOString(), 'past')
65
+ const future = await request(new Date(Date.now() + BED255_SIG_TTL + 1_000).toISOString(), 'future')
66
+
67
+ await expect(handle(past.guard, past.req)).rejects.toBeInstanceOf(AuthenPayloadError)
68
+ await expect(handle(future.guard, future.req)).rejects.toBeInstanceOf(AuthenPayloadError)
69
+ })
70
+
71
+ test('rejects authentication when an injected replay store fails', async () => {
72
+ const signed = await request(new Date().toISOString(), 'store-failure')
73
+ const guard = makeBasicEd25519Guard(TRUSTED_ALIAS, {
74
+ replay: { claim: async () => { throw new Error('store unavailable') } }
75
+ })
76
+ signed.fixture.ctx.registerService(guard)
77
+
78
+ await expect(handle(guard, signed.req)).rejects.toBeInstanceOf(AuthenPayloadError)
79
+ })
80
+
81
+ test('adapts a create-once resource and forwards the absolute signed expiry', async () => {
82
+ let claimed = false
83
+ let observedExpiry: Date | undefined
84
+ const resource = {
85
+ create: async (record: { id?: string }, opts?: { ttl?: number | Date }) => {
86
+ if (claimed) throw new RecordExists(record.id ?? '')
87
+ claimed = true
88
+ observedExpiry = opts?.ttl as Date
89
+ return record
90
+ }
91
+ } as SignedRequestReplayResource
92
+ const replay = makeResourceSignedRequestReplayStore(resource)
93
+ const expiresAt = new Date(Date.now() + BED255_SIG_TTL)
94
+
95
+ expect(await replay.claim('service:nonce', expiresAt)).toBe(true)
96
+ expect(observedExpiry).toBe(expiresAt)
97
+ expect(await replay.claim('service:nonce', expiresAt)).toBe(false)
98
+ })
99
+ })
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
  })
@@ -0,0 +1,112 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { AppType, createService, makeBasicContext } from '@owlmeans/context'
3
+ import type { BasicConfig, BasicContext } from '@owlmeans/context'
4
+ import { AuthenFailed, AuthRole } from '@owlmeans/auth'
5
+ import type { Auth } from '@owlmeans/auth'
6
+ import type { AbstractRequest, ResolvedEntity } from '@owlmeans/entrypoint'
7
+ import { makeEntityScope } from '../src/entity.js'
8
+ import { ENTITY_RESOLVER } from '../src/consts.js'
9
+ import type { EntityResolverService, OrgEntityRef } from '../src/types.js'
10
+
11
+ const ACME: OrgEntityRef = { id: '0123456789abcdef01234567', slug: 'acme', formerSlugs: ['acme-old'], iamKey: 'acme-key' }
12
+
13
+ /** A context with an in-memory registry of one organization, or none at all. */
14
+ const contextWith = async (registry?: OrgEntityRef[]) => {
15
+ const ctx = makeBasicContext<BasicConfig>({ ready: false, service: 'entity-tests', type: AppType.Backend })
16
+ const calls: string[] = []
17
+ if (registry != null) {
18
+ ctx.registerService(createService<EntityResolverService>(ENTITY_RESOLVER, {
19
+ resolve: async value => {
20
+ calls.push(value)
21
+ return registry.find(entity => entity.id === value || entity.slug === value
22
+ || entity.formerSlugs?.includes(value) || entity.iamKey === value) ?? null
23
+ },
24
+ byId: async id => registry.find(entity => entity.id === id) ?? null,
25
+ mintSlug: async () => 'minted',
26
+ rename: async () => { throw new Error('not used') },
27
+ mintName: async () => { throw new Error('not used') },
28
+ }))
29
+ }
30
+ ctx.configure()
31
+ await ctx.init()
32
+
33
+ return { ctx: ctx as BasicContext<BasicConfig>, calls }
34
+ }
35
+
36
+ const requestFor = (entitySlug?: string, entity?: ResolvedEntity): AbstractRequest => ({
37
+ alias: 'any', path: '/', params: {}, query: {}, headers: {},
38
+ auth: { token: 't', type: 'oidc', userId: 'u', role: AuthRole.User, scopes: [], isUser: true,
39
+ createdAt: new Date(), ...(entitySlug != null ? { entitySlug } : {}) } as Auth,
40
+ ...(entity != null ? { entity } : {}),
41
+ })
42
+
43
+ const attached: ResolvedEntity = { id: 'iam-key-tenant', slug: 'tenant', iamKey: 'iam-key-tenant' }
44
+
45
+ describe('attachEntity — an entity the guard attached', () => {
46
+ test('is kept when its slug is the token one, with no resolver registered', async () => {
47
+ const { ctx } = await contextWith()
48
+ const request = requestFor('tenant', attached)
49
+
50
+ expect(await makeEntityScope(request).attachEntity(ctx)).toEqual(attached)
51
+ expect(request.entity).toEqual(attached)
52
+ })
53
+
54
+ test('is kept without asking a registered resolver', async () => {
55
+ const { ctx, calls } = await contextWith([ACME])
56
+ const request = requestFor('tenant', attached)
57
+
58
+ expect(await makeEntityScope(request).attachEntity(ctx)).toEqual(attached)
59
+ expect(calls).toEqual([])
60
+ })
61
+
62
+ test('with another slug falls through to the resolver', async () => {
63
+ const { ctx, calls } = await contextWith([ACME])
64
+ const request = requestFor('acme', attached)
65
+
66
+ expect(await makeEntityScope(request).attachEntity(ctx)).toEqual(ACME)
67
+ expect(request.entity).toEqual(ACME)
68
+ expect(calls).toEqual(['acme'])
69
+ })
70
+
71
+ test('with another slug and no resolver is dropped, never trusted', async () => {
72
+ const { ctx } = await contextWith()
73
+ const request = requestFor('acme', attached)
74
+
75
+ expect(await makeEntityScope(request).attachEntity(ctx)).toBeUndefined()
76
+ expect(request.entity).toBeUndefined()
77
+ })
78
+
79
+ test('on a token naming no organization is dropped', async () => {
80
+ const { ctx } = await contextWith()
81
+ const request = requestFor(undefined, attached)
82
+
83
+ expect(await makeEntityScope(request).attachEntity(ctx)).toBeUndefined()
84
+ expect(request.entity).toBeUndefined()
85
+ })
86
+ })
87
+
88
+ describe('attachEntity — the resolver path', () => {
89
+ test('resolves and canonicalizes a retired slug', async () => {
90
+ const { ctx } = await contextWith([ACME])
91
+ const request = requestFor('acme-old')
92
+
93
+ expect(await makeEntityScope(request).attachEntity(ctx)).toEqual(ACME)
94
+ expect(request.entity).toEqual(ACME)
95
+ expect(request.auth?.entitySlug).toBe('acme')
96
+ })
97
+
98
+ test('refuses a token naming an organization the registry does not know', async () => {
99
+ const { ctx } = await contextWith([ACME])
100
+
101
+ await expect(makeEntityScope(requestFor('nobody')).attachEntity(ctx)).rejects.toBeInstanceOf(AuthenFailed)
102
+ })
103
+
104
+ test('is a no-op with no resolver and nothing attached', async () => {
105
+ const { ctx } = await contextWith()
106
+ const request = requestFor('acme')
107
+
108
+ expect(await makeEntityScope(request).attachEntity(ctx)).toBeUndefined()
109
+ expect(request.entity).toBeUndefined()
110
+ expect(request.auth?.entitySlug).toBe('acme')
111
+ })
112
+ })
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)