@owlmeans/client-auth 0.1.18-rc.9 → 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 (255) hide show
  1. package/README.md +283 -37
  2. package/agent-meta/manifest.json +50 -4
  3. package/agent-meta/skills/client-auth/SKILL.md +84 -55
  4. package/agent-meta/skills/client-auth/parts/login.md +77 -0
  5. package/agent-meta/skills/client-auth/parts/manager.md +37 -0
  6. package/build/components/dispatcher/component.d.ts.map +1 -1
  7. package/build/components/dispatcher/component.js +26 -6
  8. package/build/components/dispatcher/component.js.map +1 -1
  9. package/build/components/dispatcher/types.local.d.ts +7 -0
  10. package/build/components/dispatcher/types.local.d.ts.map +1 -0
  11. package/build/components/dispatcher/types.local.js +2 -0
  12. package/build/components/dispatcher/types.local.js.map +1 -0
  13. package/build/entrypoints.d.ts +7 -0
  14. package/build/entrypoints.d.ts.map +1 -0
  15. package/build/entrypoints.js +7 -0
  16. package/build/entrypoints.js.map +1 -0
  17. package/build/helper.d.ts +2 -1
  18. package/build/helper.d.ts.map +1 -1
  19. package/build/helper.js +28 -5
  20. package/build/helper.js.map +1 -1
  21. package/build/index.d.ts +1 -1
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +1 -1
  24. package/build/index.js.map +1 -1
  25. package/build/login/adopt/types.d.ts +26 -0
  26. package/build/login/adopt/types.d.ts.map +1 -0
  27. package/build/login/adopt/types.js +2 -0
  28. package/build/login/adopt/types.js.map +1 -0
  29. package/build/login/adopt.d.ts +7 -12
  30. package/build/login/adopt.d.ts.map +1 -1
  31. package/build/login/adopt.js +15 -14
  32. package/build/login/adopt.js.map +1 -1
  33. package/build/login/consts.d.ts +89 -4
  34. package/build/login/consts.d.ts.map +1 -1
  35. package/build/login/consts.js +93 -5
  36. package/build/login/consts.js.map +1 -1
  37. package/build/login/consts.local.d.ts +16 -0
  38. package/build/login/consts.local.d.ts.map +1 -0
  39. package/build/login/consts.local.js +30 -0
  40. package/build/login/consts.local.js.map +1 -0
  41. package/build/login/credit/types.d.ts +7 -0
  42. package/build/login/credit/types.d.ts.map +1 -0
  43. package/build/login/credit/types.js +2 -0
  44. package/build/login/credit/types.js.map +1 -0
  45. package/build/login/credit.d.ts +19 -0
  46. package/build/login/credit.d.ts.map +1 -0
  47. package/build/login/credit.js +58 -0
  48. package/build/login/credit.js.map +1 -0
  49. package/build/login/env/types.d.ts +35 -0
  50. package/build/login/env/types.d.ts.map +1 -0
  51. package/build/login/env/types.js +2 -0
  52. package/build/login/env/types.js.map +1 -0
  53. package/build/login/env.d.ts +5 -29
  54. package/build/login/env.d.ts.map +1 -1
  55. package/build/login/env.js +63 -80
  56. package/build/login/env.js.map +1 -1
  57. package/build/login/flow.d.ts +20 -0
  58. package/build/login/flow.d.ts.map +1 -0
  59. package/build/login/flow.js +39 -0
  60. package/build/login/flow.js.map +1 -0
  61. package/build/login/hook.d.ts +30 -4
  62. package/build/login/hook.d.ts.map +1 -1
  63. package/build/login/hook.js +53 -18
  64. package/build/login/hook.js.map +1 -1
  65. package/build/login/i18n/be.json +41 -0
  66. package/build/login/i18n/de.json +41 -0
  67. package/build/login/i18n/en.json +41 -0
  68. package/build/login/i18n/es.json +41 -0
  69. package/build/login/i18n/fr.json +41 -0
  70. package/build/login/i18n/pl.json +41 -0
  71. package/build/login/i18n/ru.json +41 -0
  72. package/build/login/i18n/uk.json +41 -0
  73. package/build/login/i18n.d.ts +2 -0
  74. package/build/login/i18n.d.ts.map +1 -0
  75. package/build/login/i18n.js +27 -0
  76. package/build/login/i18n.js.map +1 -0
  77. package/build/login/index.d.ts +20 -0
  78. package/build/login/index.d.ts.map +1 -1
  79. package/build/login/index.js +11 -0
  80. package/build/login/index.js.map +1 -1
  81. package/build/login/land/types.d.ts +52 -0
  82. package/build/login/land/types.d.ts.map +1 -0
  83. package/build/login/land/types.js +2 -0
  84. package/build/login/land/types.js.map +1 -0
  85. package/build/login/land.d.ts +6 -0
  86. package/build/login/land.d.ts.map +1 -0
  87. package/build/login/land.js +122 -0
  88. package/build/login/land.js.map +1 -0
  89. package/build/login/methods/types.d.ts +30 -0
  90. package/build/login/methods/types.d.ts.map +1 -0
  91. package/build/login/methods/types.js +2 -0
  92. package/build/login/methods/types.js.map +1 -0
  93. package/build/login/methods.d.ts +7 -0
  94. package/build/login/methods.d.ts.map +1 -0
  95. package/build/login/methods.js +87 -0
  96. package/build/login/methods.js.map +1 -0
  97. package/build/login/resume/types.d.ts +24 -0
  98. package/build/login/resume/types.d.ts.map +1 -0
  99. package/build/login/resume/types.js +2 -0
  100. package/build/login/resume/types.js.map +1 -0
  101. package/build/login/resume.d.ts +9 -0
  102. package/build/login/resume.d.ts.map +1 -0
  103. package/build/login/resume.js +38 -0
  104. package/build/login/resume.js.map +1 -0
  105. package/build/login/screen.d.ts +17 -0
  106. package/build/login/screen.d.ts.map +1 -0
  107. package/build/login/screen.js +66 -0
  108. package/build/login/screen.js.map +1 -0
  109. package/build/login/service.d.ts +6 -5
  110. package/build/login/service.d.ts.map +1 -1
  111. package/build/login/service.js +141 -15
  112. package/build/login/service.js.map +1 -1
  113. package/build/login/start/types.d.ts +29 -0
  114. package/build/login/start/types.d.ts.map +1 -0
  115. package/build/login/start/types.js +2 -0
  116. package/build/login/start/types.js.map +1 -0
  117. package/build/login/start.d.ts +5 -0
  118. package/build/login/start.d.ts.map +1 -0
  119. package/build/login/start.js +36 -0
  120. package/build/login/start.js.map +1 -0
  121. package/build/login/surrogate/types.d.ts +9 -0
  122. package/build/login/surrogate/types.d.ts.map +1 -0
  123. package/build/login/surrogate/types.js +2 -0
  124. package/build/login/surrogate/types.js.map +1 -0
  125. package/build/login/surrogate.d.ts +13 -0
  126. package/build/login/surrogate.d.ts.map +1 -0
  127. package/build/login/surrogate.js +33 -0
  128. package/build/login/surrogate.js.map +1 -0
  129. package/build/login/terms/types.d.ts +112 -0
  130. package/build/login/terms/types.d.ts.map +1 -0
  131. package/build/login/terms/types.js +2 -0
  132. package/build/login/terms/types.js.map +1 -0
  133. package/build/login/terms-config.d.ts +65 -0
  134. package/build/login/terms-config.d.ts.map +1 -0
  135. package/build/login/terms-config.js +2 -0
  136. package/build/login/terms-config.js.map +1 -0
  137. package/build/login/terms.d.ts +21 -0
  138. package/build/login/terms.d.ts.map +1 -0
  139. package/build/login/terms.js +235 -0
  140. package/build/login/terms.js.map +1 -0
  141. package/build/login/types.d.ts +223 -16
  142. package/build/login/types.d.ts.map +1 -1
  143. package/build/login/types.js +1 -16
  144. package/build/login/types.js.map +1 -1
  145. package/build/manager/components/authentication/control.js +3 -3
  146. package/build/manager/components/authentication/control.js.map +1 -1
  147. package/build/manager/components/authentication/types.d.ts +2 -2
  148. package/build/manager/components/authentication/types.d.ts.map +1 -1
  149. package/build/manager/components/tunnel-consumer.js +2 -2
  150. package/build/manager/components/tunnel-consumer.js.map +1 -1
  151. package/build/manager/entrypoints.d.ts +11 -0
  152. package/build/manager/entrypoints.d.ts.map +1 -0
  153. package/build/manager/entrypoints.js +17 -0
  154. package/build/manager/entrypoints.js.map +1 -0
  155. package/build/manager/plugins/basic-ed25519.d.ts.map +1 -1
  156. package/build/manager/plugins/basic-ed25519.js +5 -0
  157. package/build/manager/plugins/basic-ed25519.js.map +1 -1
  158. package/build/manager/plugins/exports.d.ts +3 -0
  159. package/build/manager/plugins/exports.d.ts.map +1 -1
  160. package/build/manager/plugins/exports.js +2 -0
  161. package/build/manager/plugins/exports.js.map +1 -1
  162. package/build/manager/plugins/index.d.ts +2 -5
  163. package/build/manager/plugins/index.d.ts.map +1 -1
  164. package/build/manager/plugins/index.js +9 -1
  165. package/build/manager/plugins/index.js.map +1 -1
  166. package/build/manager/plugins/methods.d.ts +6 -0
  167. package/build/manager/plugins/methods.d.ts.map +1 -0
  168. package/build/manager/plugins/methods.js +65 -0
  169. package/build/manager/plugins/methods.js.map +1 -0
  170. package/build/manager/plugins/re-captcha.d.ts.map +1 -1
  171. package/build/manager/plugins/re-captcha.js +5 -0
  172. package/build/manager/plugins/re-captcha.js.map +1 -1
  173. package/build/manager/plugins/registry/types.d.ts +10 -0
  174. package/build/manager/plugins/registry/types.d.ts.map +1 -0
  175. package/build/manager/plugins/registry/types.js +2 -0
  176. package/build/manager/plugins/registry/types.js.map +1 -0
  177. package/build/manager/plugins/registry.d.ts +20 -0
  178. package/build/manager/plugins/registry.d.ts.map +1 -0
  179. package/build/manager/plugins/registry.js +23 -0
  180. package/build/manager/plugins/registry.js.map +1 -0
  181. package/build/manager/plugins/tunnel-consumer.d.ts.map +1 -1
  182. package/build/manager/plugins/tunnel-consumer.js +10 -3
  183. package/build/manager/plugins/tunnel-consumer.js.map +1 -1
  184. package/build/manager/plugins/types.d.ts +53 -0
  185. package/build/manager/plugins/types.d.ts.map +1 -1
  186. package/build/modules.d.ts.map +1 -1
  187. package/build/service.js +1 -1
  188. package/build/service.js.map +1 -1
  189. package/package.json +33 -30
  190. package/src/components/dispatcher/component.tsx +37 -14
  191. package/src/components/dispatcher/types.local.ts +7 -0
  192. package/src/entrypoints.ts +10 -0
  193. package/src/helper.ts +31 -5
  194. package/src/index.ts +1 -1
  195. package/src/login/adopt/types.ts +25 -0
  196. package/src/login/adopt.ts +21 -14
  197. package/src/login/consts.local.ts +34 -0
  198. package/src/login/consts.ts +105 -5
  199. package/src/login/credit/types.ts +6 -0
  200. package/src/login/credit.ts +69 -0
  201. package/src/login/env/types.ts +35 -0
  202. package/src/login/env.ts +60 -72
  203. package/src/login/flow.ts +44 -0
  204. package/src/login/hook.ts +58 -22
  205. package/src/login/i18n/be.json +41 -0
  206. package/src/login/i18n/de.json +41 -0
  207. package/src/login/i18n/en.json +41 -0
  208. package/src/login/i18n/es.json +41 -0
  209. package/src/login/i18n/fr.json +41 -0
  210. package/src/login/i18n/pl.json +41 -0
  211. package/src/login/i18n/ru.json +41 -0
  212. package/src/login/i18n/uk.json +41 -0
  213. package/src/login/i18n.ts +29 -0
  214. package/src/login/index.ts +21 -0
  215. package/src/login/land/types.ts +54 -0
  216. package/src/login/land.ts +149 -0
  217. package/src/login/methods/types.ts +32 -0
  218. package/src/login/methods.ts +109 -0
  219. package/src/login/resume/types.ts +24 -0
  220. package/src/login/resume.ts +45 -0
  221. package/src/login/screen.tsx +140 -0
  222. package/src/login/service.ts +181 -18
  223. package/src/login/start/types.ts +30 -0
  224. package/src/login/start.ts +44 -0
  225. package/src/login/surrogate/types.ts +9 -0
  226. package/src/login/surrogate.ts +37 -0
  227. package/src/login/terms/types.ts +126 -0
  228. package/src/login/terms-config.ts +55 -0
  229. package/src/login/terms.ts +315 -0
  230. package/src/login/types.ts +233 -17
  231. package/src/manager/README.md +37 -80
  232. package/src/manager/components/authentication/control.ts +3 -3
  233. package/src/manager/components/authentication/types.ts +2 -2
  234. package/src/manager/components/tunnel-consumer.tsx +2 -2
  235. package/src/manager/entrypoints.ts +18 -0
  236. package/src/manager/plugins/basic-ed25519.tsx +7 -0
  237. package/src/manager/plugins/exports.ts +3 -0
  238. package/src/manager/plugins/index.ts +11 -4
  239. package/src/manager/plugins/methods.ts +74 -0
  240. package/src/manager/plugins/re-captcha.tsx +7 -0
  241. package/src/manager/plugins/registry/types.ts +10 -0
  242. package/src/manager/plugins/registry.ts +33 -0
  243. package/src/manager/plugins/tunnel-consumer.tsx +12 -3
  244. package/src/manager/plugins/types.ts +54 -0
  245. package/src/service.ts +1 -1
  246. package/tests/context.ts +1 -2
  247. package/tests/i18n.spec.ts +68 -0
  248. package/tests/land.spec.ts +292 -0
  249. package/tests/login.spec.ts +332 -0
  250. package/tests/target.spec.ts +210 -0
  251. package/tests/terms-deferred.spec.ts +65 -0
  252. package/tests/terms.spec.ts +314 -0
  253. package/build/.gitkeep +0 -0
  254. package/src/manager/modules.ts +0 -18
  255. package/src/modules.ts +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/client-auth",
3
- "version": "0.1.18-rc.9",
3
+ "version": "0.1.18",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -27,12 +27,12 @@
27
27
  "module": "./build/manager/index.js",
28
28
  "types": "./build/manager/index.d.ts"
29
29
  },
30
- "./manager/modules": {
31
- "import": "./build/manager/modules.js",
32
- "require": "./build/manager/modules.js",
33
- "default": "./build/manager/modules.js",
34
- "module": "./build/manager/modules.js",
35
- "types": "./build/manager/modules.d.ts"
30
+ "./manager/entrypoints": {
31
+ "import": "./build/manager/entrypoints.js",
32
+ "require": "./build/manager/entrypoints.js",
33
+ "default": "./build/manager/entrypoints.js",
34
+ "module": "./build/manager/entrypoints.js",
35
+ "types": "./build/manager/entrypoints.d.ts"
36
36
  },
37
37
  "./manager/plugins": {
38
38
  "import": "./build/manager/plugins/exports.js",
@@ -50,35 +50,38 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@owlmeans/auth": "^0.1.18-rc.6",
54
- "@owlmeans/auth-common": "^0.1.18-rc.7",
55
- "@owlmeans/basic-envelope": "^0.1.18-rc.7",
56
- "@owlmeans/basic-keys": "^0.1.18-rc.7",
57
- "@owlmeans/client": "^0.1.18-rc.8",
58
- "@owlmeans/client-context": "^0.1.18-rc.7",
59
- "@owlmeans/client-flow": "^0.1.18-rc.7",
60
- "@owlmeans/client-entrypoint": "^0.1.18-rc.7",
61
- "@owlmeans/client-resource": "^0.1.18-rc.7",
62
- "@owlmeans/client-socket": "^0.1.18-rc.7",
63
- "@owlmeans/context": "^0.1.18-rc.6",
64
- "@owlmeans/did": "^0.1.18-rc.7",
65
- "@owlmeans/error": "^0.1.18-rc.6",
66
- "@owlmeans/flow": "^0.1.18-rc.7",
67
- "@owlmeans/entrypoint": "^0.1.18-rc.7",
68
- "@owlmeans/resource": "^0.1.18-rc.7",
69
- "@owlmeans/socket": "^0.1.18-rc.6",
70
- "@owlmeans/web-flow": "^0.1.18-rc.7",
71
- "@scure/base": "^2.3.0"
53
+ "@owlmeans/auth": "^0.1.18",
54
+ "@owlmeans/auth-common": "^0.1.18",
55
+ "@owlmeans/basic-envelope": "^0.1.18",
56
+ "@owlmeans/basic-keys": "^0.1.18",
57
+ "@owlmeans/client": "^0.1.18",
58
+ "@owlmeans/client-context": "^0.1.18",
59
+ "@owlmeans/client-entrypoint": "^0.1.18",
60
+ "@owlmeans/client-flow": "^0.1.18",
61
+ "@owlmeans/client-resource": "^0.1.18",
62
+ "@owlmeans/client-socket": "^0.1.18",
63
+ "@owlmeans/config": "^0.1.18",
64
+ "@owlmeans/context": "^0.1.18",
65
+ "@owlmeans/did": "^0.1.18",
66
+ "@owlmeans/entrypoint": "^0.1.18",
67
+ "@owlmeans/error": "^0.1.18",
68
+ "@owlmeans/flow": "^0.1.18",
69
+ "@owlmeans/i18n": "^0.1.18",
70
+ "@owlmeans/log": "^0.1.18",
71
+ "@owlmeans/resource": "^0.1.18",
72
+ "@owlmeans/socket": "^0.1.18",
73
+ "@owlmeans/web-flow": "^0.1.18",
74
+ "@scure/base": "^2.4.0"
72
75
  },
73
76
  "peerDependencies": {
74
77
  "ajv": "*",
75
78
  "react": "*"
76
79
  },
77
80
  "devDependencies": {
78
- "@owlmeans/dep-config": "workspace:*",
79
- "@owlmeans/test-auth": "^0.1.18-rc.7",
80
- "@types/bun": "^1.3.14",
81
- "@types/react": "^19.2.17",
81
+ "@owlmeans/dep-config": "^0.1.18",
82
+ "@owlmeans/test-auth": "^0.1.18",
83
+ "@types/bun": "^1.4.2",
84
+ "@types/react": "^19.3.0",
82
85
  "nodemon": "^3.1.14",
83
86
  "typescript": "^7.0.2"
84
87
  },
@@ -1,34 +1,61 @@
1
1
  import { useCallback, useEffect, useState } from 'react'
2
2
  import type { DispatcherRendererProps, TDispatcherHOC } from './types.js'
3
- import type { AuthToken } from '@owlmeans/auth'
4
3
  import { AUTH_QUERY, DISPATCHER } from '@owlmeans/auth'
5
4
  import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
6
5
  import { HOME } from '@owlmeans/context'
7
6
  import { DEFAULT_ALIAS, DEFAULT_ENTITY } from '../../consts.js'
8
7
  import type { AuthService } from '@owlmeans/auth-common'
9
8
  import { useNavigate } from '@owlmeans/client'
10
- import type { AbstractRequest } from '@owlmeans/entrypoint'
11
- import type { FlowService } from '@owlmeans/client-flow'
12
- import { DEFAULT_ALIAS as FLOW_SERVICE } from '@owlmeans/client-flow'
9
+ import { type FlowService, DEFAULT_ALIAS as FLOW_SERVICE } from '@owlmeans/client-flow'
13
10
  import { FLOW_PLACEHOLDER, OidcAuthStep, STD_OIDC_FLOW } from '@owlmeans/flow'
14
11
  import { SERVICE_PARAM } from '@owlmeans/web-flow'
12
+ import { loginLandingOf } from '../../login/land.js'
13
+ import { logger } from '@owlmeans/log'
14
+ import type { StateToken } from './types.local.js'
15
+
16
+ const log = logger('client-auth:dispatcher')
15
17
 
16
18
  export const DispatcherHOC: TDispatcherHOC = Renderer => ({ context, params, alias, query, payload }) => {
17
19
  const [forwarding, setForwarding] = useState<StateToken | undefined>()
18
20
 
19
21
  const navigator = useNavigate()
20
22
  const navigate = useCallback(async () => {
21
- alias = alias == null || alias === DISPATCHER ? HOME : alias
22
- const module = context.module<ClientEntrypoint<string>>(alias)
23
- if (alias === HOME) {
24
- params = {}
25
- query = {}
23
+ if (alias == null || alias === DISPATCHER) {
24
+ // A sign-in that started elsewhere — a device or authorization-code consent screen, most
25
+ // commonly — suspended itself here before leaving, or a registered step still has
26
+ // something to collect (a marketing-consent screen, say). `landAfterLogin` is the whole
27
+ // post-sign-in landing decision (steps, landing hooks, the suspended flow, then HOME) and
28
+ // takes priority over the ordinary HOME landing, resolved BEFORE `alias` is overwritten,
29
+ // because once it is `HOME` there is no way back to tell the cases apart.
30
+ const landing = await loginLandingOf(context).landAfterLogin()
31
+ if (landing.alias !== HOME) {
32
+ await navigator.navigate(
33
+ context.entrypoint<ClientEntrypoint<string>>(landing.alias),
34
+ { params: landing.params, query: landing.query }
35
+ )
36
+ return
37
+ }
38
+ alias = HOME
26
39
  } else {
40
+ // A concrete destination already exists (an OIDC `?code=` return, etc.) — a registered step
41
+ // still gets to interject, but `resumeSuspendedFlow` must not run a second time: this
42
+ // branch already has somewhere to go.
27
43
  query = { ...forwarding?.query, ...query }
28
44
  if (query != null && AUTH_QUERY in query) {
29
45
  delete query[AUTH_QUERY]
30
46
  }
47
+ const landing = await loginLandingOf(context).landAfterLogin(
48
+ { fallback: { alias, params, query }, resume: false }
49
+ )
50
+ await navigator.navigate(
51
+ context.entrypoint<ClientEntrypoint<string>>(landing.alias),
52
+ { params: landing.params, query: landing.query }
53
+ )
54
+ return
31
55
  }
56
+ const module = context.entrypoint<ClientEntrypoint<string>>(alias)
57
+ params = {}
58
+ query = {}
32
59
  await navigator.navigate(module, { params, query })
33
60
  }, [forwarding])
34
61
 
@@ -78,7 +105,7 @@ export const DispatcherHOC: TDispatcherHOC = Renderer => ({ context, params, ali
78
105
  return await navigate()
79
106
  }).catch((e: Error) => {
80
107
  // @TODO Show error on the component
81
- console.error(e)
108
+ log.error('Authentication failed', e, { event: 'auth.refused' })
82
109
  })
83
110
  }
84
111
  }
@@ -91,7 +118,3 @@ export const DispatcherHOC: TDispatcherHOC = Renderer => ({ context, params, ali
91
118
  return <Renderer provideToken={provideToken} navigate={navigate} />
92
119
  }
93
120
 
94
- interface StateToken {
95
- token: AuthToken
96
- query?: AbstractRequest['params']
97
- }
@@ -0,0 +1,7 @@
1
+ import type { AuthToken } from '@owlmeans/auth'
2
+ import type { AbstractRequest } from '@owlmeans/entrypoint'
3
+
4
+ export interface StateToken {
5
+ token: AuthToken
6
+ query?: AbstractRequest['params']
7
+ }
@@ -0,0 +1,10 @@
1
+
2
+ import { bind, bindScreen, stab } from '@owlmeans/client-entrypoint'
3
+ import { authProtocols } from '@owlmeans/auth-common'
4
+
5
+ /** Browser entrypoints for the authentication protocols every client may call. */
6
+ export const entrypoints = [bind(authProtocols.dispatcherAuthenticate)]
7
+
8
+ /** Bind the external-authentication screen to one explicitly selected service. */
9
+ export const bindExternalAuthentication = (service: string) =>
10
+ bindScreen(authProtocols.flowEnter, stab, { routeOptions: { overrides: { service } } })
package/src/helper.ts CHANGED
@@ -1,18 +1,22 @@
1
1
  import { useContext, useNavigate } from '@owlmeans/client'
2
2
  import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
3
- import { provideRequest } from '@owlmeans/client-entrypoint'
4
3
  import { useWs as useWebSocket } from '@owlmeans/client-socket'
4
+ import type { WsOptions } from '@owlmeans/client-socket'
5
5
  import type { AbstractRequest } from '@owlmeans/entrypoint'
6
6
  import type { AuthServiceAppend } from './types.js'
7
7
  import { useEffect, useMemo, useState } from 'react'
8
8
  import type { ClientContext } from '@owlmeans/client-context'
9
9
  import { AUTH_QUERY, DISPATCHER } from '@owlmeans/auth'
10
+ import { logger } from '@owlmeans/log'
11
+ import { clientRequestHelper } from '@owlmeans/client-entrypoint'
12
+
13
+ const log = logger('client-auth')
10
14
  // import { useFlow } from '@owlmeans/web-flow'
11
15
  // import { DEFAULT_ENTITY } from './consts.js'
12
16
  // import { OidcAuthStep } from '@owlmeans/flow'
13
17
 
14
18
  export const useWs = (
15
- module: string | ClientEntrypoint<any>, _request?: Partial<AbstractRequest<any>>
19
+ module: string | ClientEntrypoint<any>, _request?: Partial<AbstractRequest<any>>, options?: WsOptions
16
20
  ) => {
17
21
  const ctx = useContext() as unknown as AuthServiceAppend & ClientContext
18
22
 
@@ -20,9 +24,13 @@ export const useWs = (
20
24
  () => typeof module === 'string' ? ctx.entrypoint<ClientEntrypoint>(module) : module, [module]
21
25
  )
22
26
 
27
+ // Captured before the token is filled in below, so a caller who supplied their own token
28
+ // keeps full control of it across a reconnect too — `beforeConnect` only refreshes ours.
29
+ const callerSuppliedToken = _request?.query?.[AUTH_QUERY] != null
30
+
23
31
  const request = useMemo(() => {
24
32
  if (_request == null) {
25
- _request = provideRequest(mod.getAlias(), mod.getPath())
33
+ _request = clientRequestHelper.provideRequest(mod.alias, mod.path())
26
34
  }
27
35
  try {
28
36
  if (_request?.query?.[AUTH_QUERY] == null) {
@@ -32,13 +40,31 @@ export const useWs = (
32
40
  _request.query[AUTH_QUERY] = ctx.auth().token
33
41
  }
34
42
  } catch (e) {
35
- console.error(e)
43
+ log.warn('Socket auth token not attached', e)
36
44
  }
37
45
 
38
46
  return _request
39
47
  }, [_request])
40
48
 
41
- return useWebSocket(module, request)
49
+ const wsOptions = useMemo<WsOptions>(() => ({
50
+ ...options,
51
+ beforeConnect: async req => {
52
+ // A reconnect can land minutes after the socket first opened — refresh the bearer token
53
+ // on every attempt rather than trust the one `request` was built with, or a token rotated
54
+ // in between reopens the socket with a stale one the guard then rejects.
55
+ if (!callerSuppliedToken) {
56
+ try {
57
+ req.query ??= {}
58
+ req.query[AUTH_QUERY] = ctx.auth().token
59
+ } catch (e) {
60
+ log.warn('Socket auth token not refreshed', e)
61
+ }
62
+ }
63
+ await options?.beforeConnect?.(req)
64
+ }
65
+ }), [options, callerSuppliedToken])
66
+
67
+ return useWebSocket(module, request, wsOptions)
42
68
  }
43
69
 
44
70
  export const useSelfAuth = (force: boolean = true/*, entity: string = DEFAULT_ENTITY*/) => {
package/src/index.ts CHANGED
@@ -3,5 +3,5 @@ export * from './components/index.js'
3
3
  export type * from './types.js'
4
4
  export * from './service.js'
5
5
  export * from './consts.js'
6
- export * from './modules.js'
6
+ export * from './entrypoints.js'
7
7
  export * from './helper.js'
@@ -0,0 +1,25 @@
1
+ /** The two paths a context's authentication changes by: a token adopted, a token dropped. */
2
+ export interface LoginTokenHelper {
3
+ /**
4
+ * The one path an issued bearer token becomes this context's authentication.
5
+ *
6
+ * Resolved by alias rather than through `ctx.auth()` so the login host does not require
7
+ * `AuthServiceAppend` on the context it is given — a plugin can adopt a token on any context that
8
+ * carries the auth service, including one it did not build.
9
+ *
10
+ * Going through `AuthService.update` matters: it stores the record, decodes the envelope and sets
11
+ * both `auth` and `token` in one place. Writing those three by hand — which is what the popup and
12
+ * the MUI relying party each used to do — leaves the same state on a good day and diverges the
13
+ * moment any of it changes.
14
+ */
15
+ adoptToken: (token: string) => Promise<void>
16
+ /**
17
+ * The one path this context's authentication is dropped, and the exact mirror of {@link adoptToken}.
18
+ *
19
+ * `undefined`, not `null`: `undefined` is the declared clearing value, and on the web the auth
20
+ * service reacts to it by navigating to the dispatcher. Everything that signs a user out goes
21
+ * through here — the hook, both browser plugins and the surrogate screen — so there is one place
22
+ * where "signed out" is defined rather than four that agree until one of them changes.
23
+ */
24
+ revokeToken: () => Promise<void>
25
+ }
@@ -1,19 +1,26 @@
1
1
  import type { AuthService } from '@owlmeans/auth-common'
2
+ import { memoHelper } from '@owlmeans/context'
2
3
  import { DEFAULT_ALIAS as AUTH_ALIAS } from '../consts.js'
3
4
  import type { LoginContext } from './types.js'
5
+ import type { LoginTokenHelper } from './adopt/types.js'
4
6
 
5
- /**
6
- * The one path an issued bearer token becomes this context's authentication.
7
- *
8
- * Resolved by alias rather than through `ctx.auth()` so the login host does not require
9
- * `AuthServiceAppend` on the context it is given — a plugin can adopt a token on any context that
10
- * carries the auth service, including one it did not build.
11
- *
12
- * Going through `AuthService.update` matters: it stores the record, decodes the envelope and sets
13
- * both `auth` and `token` in one place. Writing those three by hand — which is what the popup and
14
- * the MUI relying party each used to do — leaves the same state on a good day and diverges the
15
- * moment any of it changes.
16
- */
17
- export const adoptToken = async (ctx: LoginContext, token: string): Promise<void> => {
18
- await ctx.service<AuthService>(AUTH_ALIAS).update(token)
7
+ export const makeLoginTokenHelper = (ctx: LoginContext): LoginTokenHelper => {
8
+ const adoptToken = async (token: string): Promise<void> => {
9
+ await ctx.service<AuthService>(AUTH_ALIAS).update(token)
10
+ }
11
+
12
+ const revokeToken = async (): Promise<void> => {
13
+ await ctx.service<AuthService>(AUTH_ALIAS).update(undefined)
14
+ }
15
+
16
+ return { adoptToken, revokeToken }
19
17
  }
18
+
19
+ /** The token helper of a context — one per context. */
20
+ export const loginTokenOf = memoHelper.oncePer(makeLoginTokenHelper)
21
+
22
+ /** @deprecated compat:factory-refactor — use `loginTokenOf(ctx).adoptToken(…)` */
23
+ export const adoptToken = async (ctx: LoginContext, token: string): Promise<void> => loginTokenOf(ctx).adoptToken(token)
24
+
25
+ /** @deprecated compat:factory-refactor — use `loginTokenOf(ctx).revokeToken()` */
26
+ export const revokeToken = async (ctx: LoginContext): Promise<void> => loginTokenOf(ctx).revokeToken()
@@ -0,0 +1,34 @@
1
+ import { LoginOutcome } from './consts.js'
2
+ import type { CSSProperties } from 'react'
3
+
4
+ /**
5
+ * The page the card sits in.
6
+ *
7
+ * It carries its own viewport height because this screen is rendered straight out of the
8
+ * dispatcher, into whatever the application happens to have around it — which is usually nothing
9
+ * with a height, so a percentage minimum would resolve to zero and leave the card at the top.
10
+ */
11
+ export const page: CSSProperties = {
12
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
13
+ minHeight: '100dvh', padding: '1rem',
14
+ fontFamily: 'system-ui, sans-serif', lineHeight: 1.5,
15
+ }
16
+
17
+ // Centred throughout, so the plain screen and the styled one read the same way.
18
+ export const box: CSSProperties = {
19
+ width: '100%', maxWidth: '24rem', padding: '1.5rem', textAlign: 'center',
20
+ }
21
+
22
+ /** The same English fallback a document's `i18nKey` translates to when nothing else names it. */
23
+ export const DEFAULT_LABEL: Record<string, string> = {
24
+ terms: 'Terms & Conditions',
25
+ privacy: 'Privacy Policy',
26
+ cookies: 'Cookie Policy',
27
+ billing: 'Billing Terms',
28
+ product: '{{product}} Product Terms',
29
+ }
30
+
31
+ /** Outcomes after which nobody was signed in, so a screen parked for the landing must not wait. */
32
+ export const UNSIGNED_OUTCOMES: ReadonlySet<LoginOutcome> = new Set<LoginOutcome>([
33
+ LoginOutcome.Blocked, LoginOutcome.Failed, LoginOutcome.Gesture,
34
+ ])
@@ -5,20 +5,120 @@ export const LOGIN_SERVICE = DEFAULT_ALIAS
5
5
  /** Priority of a plugin that makes no claim about the environment. */
6
6
  export const DEFAULT_LOGIN_PRIORITY = 0
7
7
 
8
+ /** Order given to a method that declares none. */
9
+ export const DEFAULT_METHOD_ORDER = 100
10
+
8
11
  /**
9
- * Name given to the surrogate login window, and the marker it records about itself.
12
+ * Name given to the surrogate login window, the marker it records about itself, and the values the
13
+ * two documents exchange.
10
14
  *
11
- * These values are a wire protocol between two documents that may be running different builds —
12
- * an opener holding an older bundle and a surrogate freshly loaded, or the reverse. They are
13
- * therefore fixed, and must never be "tidied" to match a newer vocabulary.
15
+ * These are a wire protocol between two documents that may be running different builds — an opener
16
+ * holding an older bundle and a surrogate freshly loaded, or the reverse. They are therefore fixed,
17
+ * and must never be "tidied" to match a newer vocabulary. That applies to the query names and the
18
+ * message types added later just as much as to the original three.
14
19
  */
15
20
  export const LOGIN_SURROGATE_NAME = 'owlmeans-oidc-login'
16
21
 
17
22
  export const LOGIN_TOKEN_MESSAGE = 'owlmeans:oidc:popup-token'
18
23
 
24
+ export const LOGIN_LOGOUT_MESSAGE = 'owlmeans:oidc:popup-logout'
25
+
19
26
  export const LOGIN_SURROGATE_MARKER = '_owlmeans-oidc-popup'
20
27
 
21
- export const LOGIN_SURROGATE_FEATURES = 'popup=yes,width=520,height=760'
28
+ export const LOGIN_SURROGATE_WIDTH = 520
29
+
30
+ export const LOGIN_SURROGATE_HEIGHT = 760
31
+
32
+ /**
33
+ * @deprecated Never centered the window — it carried no `left`/`top`, so the surrogate always
34
+ * opened wherever the browser's own default popup placement put it. Superseded by
35
+ * `@owlmeans/web-client`'s `centeredPopupFeatures(LOGIN_SURROGATE_WIDTH, LOGIN_SURROGATE_HEIGHT)`,
36
+ * computed fresh per call since centering depends on where the browser window currently sits.
37
+ * Kept, unchanged, for the same reason as the rest of this block: an already-generated app may
38
+ * carry a copy of code that still imports it.
39
+ */
40
+ export const LOGIN_SURROGATE_FEATURES =
41
+ `popup=yes,width=${LOGIN_SURROGATE_WIDTH},height=${LOGIN_SURROGATE_HEIGHT}`
22
42
 
23
43
  /** How often a surrogate window is checked for having been closed by the user. */
24
44
  export const LOGIN_WATCH_INTERVAL = 500
45
+
46
+ /** Carries WHY the surrogate window was opened across the window boundary. */
47
+ export const LOGIN_INTENT_QUERY = 'intent'
48
+
49
+ /**
50
+ * Carries the address the surrogate should run, so the flow parameters the opener's URL held are
51
+ * forwarded rather than discarded.
52
+ */
53
+ export const LOGIN_NEXT_QUERY = 'next'
54
+
55
+ /**
56
+ * Carries the method the user already chose, one window up.
57
+ *
58
+ * A surrogate acting on it is not an auto-redirect in the "never choose for the user" sense: the
59
+ * choice was made, by a person, in the document that opened this one.
60
+ */
61
+ export const LOGIN_METHOD_QUERY = 'method'
62
+
63
+ /** Where a browser records that it agreed to one exact set of legal documents. */
64
+ export const LOGIN_TERMS_STORAGE = '_owlmeans-login-terms'
65
+
66
+ /**
67
+ * Bound on a single step's `pending` check, or a landing hook's `landed` call.
68
+ *
69
+ * A step/hook that hangs must never HANG sign-in itself — both `continueLogin` and
70
+ * `landAfterLogin` treat a timeout exactly like a rejection, resolving within this budget either
71
+ * way. What that resolves TO is fail-open ("not pending") for an ordinary step, and fail-closed
72
+ * ("pending") for one that declared itself `required` — see `continueLogin`'s `onBroken`.
73
+ */
74
+ export const LOGIN_STEP_TIMEOUT = 5_000
75
+
76
+ /** Where a browser records the last token a landing hook has already run for. */
77
+ export const LOGIN_LANDED_STORAGE = '_owlmeans-login-landed'
78
+
79
+ /** What a dispatcher does once `login().resume(...)` has answered. */
80
+ export enum ResumeAction {
81
+ /** The plugin took it over — the browser is leaving, or the window is closing. */
82
+ Stop = 'stop',
83
+ /** Render the outcome to the user; there is nothing further to do automatically. */
84
+ Render = 'render',
85
+ /** Ordinary tab: keep the session and carry on to the application. */
86
+ Navigate = 'navigate',
87
+ }
88
+
89
+ /** What a stage did, and therefore what the caller must do next. */
90
+ export enum LoginOutcome {
91
+ /** The plugin took the flow over and it is finished. The caller does nothing more. */
92
+ Handled = 'handled',
93
+ /** The plugin did nothing — the caller carries on with its ordinary continuation. */
94
+ Passed = 'passed',
95
+ /** The browser is leaving this document. The caller must not navigate or render. */
96
+ Redirected = 'redirected',
97
+ /** Cannot proceed without a fresh user gesture — the caller renders a sign-in control. */
98
+ Gesture = 'gesture',
99
+ /** Authenticated, but with no channel back to the window that started it. */
100
+ Orphaned = 'orphaned',
101
+ /** The attempt ended with no token (the user closed the window, or the provider refused it). */
102
+ Failed = 'failed',
103
+ /**
104
+ * A window this flow needed could not be opened at all — `window.open` returned `null`, which is
105
+ * the browser's own popup blocker, not a flow failure. Distinct from {@link Failed}: a caller
106
+ * with nowhere inline to render (a header "Log in"/"Log out" control, not the sign-in screen)
107
+ * needs to know specifically that a fresh click reopening the SAME control will not help, and
108
+ * that the browser is already showing its own blocked-popup affordance somewhere.
109
+ */
110
+ Blocked = 'blocked',
111
+ }
112
+
113
+ /** Why a surrogate window was opened. */
114
+ export enum LoginIntent {
115
+ Login = 'login',
116
+ Logout = 'logout',
117
+ }
118
+
119
+ /**
120
+ * How long a sign-in aimed at a screen (`LoginRequest.target`) keeps that screen parked: long
121
+ * enough for a sign-in with an emailed code, short enough that a tab abandoned mid-way never lands
122
+ * a later, unrelated sign-in on it.
123
+ */
124
+ export const LOGIN_TARGET_TTL = 30 * 60 * 1000
@@ -0,0 +1,6 @@
1
+ export interface ResolvedCredit {
2
+ /** Whether "Powered by OwlMeans" is rendered. */
3
+ poweredBy: boolean
4
+ /** The product and organization line, already composed. Null when there is nothing to say. */
5
+ line: string | null
6
+ }
@@ -0,0 +1,69 @@
1
+ import type { BrandSettings, LoginCreditConfig } from '@owlmeans/config'
2
+ import type { ResolvedCredit } from './credit/types.js'
3
+
4
+ /**
5
+ * The years one notice covers.
6
+ *
7
+ * A range only while the first year is genuinely in the past — an app configured with the current
8
+ * year, or with a year a skewed clock puts in the future, still gets a well-formed notice rather
9
+ * than `© 2026–2026` or a range that runs backwards.
10
+ */
11
+ const years = (since: number | undefined, now: number): string =>
12
+ since != null && since > 0 && since < now ? `${since}–${now}` : `${now}`
13
+
14
+ /**
15
+ * A configured value that was actually SET.
16
+ *
17
+ * Empty is how a build-time default spells "unset", and this config is filled from environment
18
+ * variables a platform delivers — `BRANDING_ORGANIZATION: meta.brandingOrganization ?? ''` is the
19
+ * shape of every one of them. `??` does not fall through an empty string, so an undelivered
20
+ * organization used to win the fallback chain and compose a line ending in a bare dash.
21
+ */
22
+ const set = (value?: string | null): string | null =>
23
+ value != null && value.trim() !== '' ? value : null
24
+
25
+ /**
26
+ * What the bottom of the sign-in screen says.
27
+ *
28
+ * It is a copyright notice, so it is composed as one: `© <year> <holder>`. That is the whole
29
+ * reason `copyright` defaults to on — the name on its own reads as a caption, and an application
30
+ * that means to assert a copyright would have had to write the mark and the year into a literal
31
+ * `line` to get one.
32
+ *
33
+ * The organization falls back to its slug because an organization record carries no readable name
34
+ * — so "no name" is the ordinary case, not an error, and a screen that rendered an empty line for
35
+ * it would be worse than one that renders the slug.
36
+ *
37
+ * `line` replaces everything when an app supplies it: a product with its own legal wording should
38
+ * not have to defeat a composition rule to use it.
39
+ */
40
+ export const resolveCredit = (
41
+ cfg?: LoginCreditConfig, brand?: BrandSettings, service?: string
42
+ ): ResolvedCredit => {
43
+ const poweredBy = cfg?.poweredBy ?? true
44
+ const literal = set(cfg?.line)
45
+ if (literal != null) {
46
+ return { poweredBy, line: literal }
47
+ }
48
+
49
+ const product = set(cfg?.product) ?? set(brand?.name) ?? set(service)
50
+ const organization = set(cfg?.organization) ?? set(brand?.organization)
51
+ ?? set(cfg?.entity) ?? set(brand?.entity)
52
+
53
+ // Whoever the notice names. A product with no organization behind it holds its own copyright,
54
+ // which is why this falls through to the product rather than dropping the notice.
55
+ const holder = set(cfg?.holder) ?? organization ?? product
56
+ const wording = typeof cfg?.copyright === 'string' ? set(cfg.copyright) : null
57
+ const notice = cfg?.copyright === false || holder == null
58
+ ? organization
59
+ : wording ?? `© ${years(cfg?.since, new Date().getFullYear())} ${holder}`
60
+
61
+ // The product is named beside the notice only when it is not already the thing being claimed —
62
+ // "OwlMeans — © 2026 OwlMeans" says the name twice and neither time usefully.
63
+ return {
64
+ poweredBy,
65
+ line: product != null && notice != null && product !== holder
66
+ ? `${product} — ${notice}`
67
+ : notice ?? product,
68
+ }
69
+ }
@@ -0,0 +1,35 @@
1
+ import type { LoginEnv } from '../types.js'
2
+
3
+ /** What this browsing context is for a sign-in: framed, the surrogate window, opened by another. */
4
+ export interface LoginEnvHelper {
5
+ /**
6
+ * Whether this document is embedded in a frame.
7
+ *
8
+ * Reading `window.top` across origins throws, and that throw is itself the answer: a `top` that
9
+ * differs and a `top` that cannot be reached both mean "framed".
10
+ */
11
+ isEmbedded: () => boolean
12
+ /**
13
+ * Record that this window is the surrogate login window, while that is still knowable.
14
+ *
15
+ * Must run on the surrogate's **first** load, before the flow navigates to the provider:
16
+ * `window.name` is the only evidence at that point, and browsers clear it as soon as a top-level
17
+ * context goes cross-origin — so by the time the provider redirects back, the name is gone and
18
+ * this window would look like an ordinary tab.
19
+ *
20
+ * Idempotent, and a no-op in every window that is not the surrogate.
21
+ */
22
+ markSurrogate: () => void
23
+ /** Whether this document is the surrogate login window. */
24
+ isSurrogate: () => boolean
25
+ /** Forget the surrogate marker — called once its token has been handed back. */
26
+ clearSurrogate: () => void
27
+ /**
28
+ * Default login environment.
29
+ *
30
+ * The single source of environment truth for cascade selection — a plugin's `match` reads this
31
+ * and never probes `window` itself, so a non-DOM host can drive the same plugins by supplying its
32
+ * own descriptor.
33
+ */
34
+ defaultLoginEnv: () => LoginEnv
35
+ }