@owlmeans/web-client 0.1.18-rc.2 → 0.1.18-rc.20

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 (85) hide show
  1. package/agent-meta/manifest.json +2 -2
  2. package/agent-meta/skills/web-client/SKILL.md +45 -10
  3. package/build/components/dispatcher/component.d.ts.map +1 -1
  4. package/build/components/dispatcher/component.js +54 -9
  5. package/build/components/dispatcher/component.js.map +1 -1
  6. package/build/context.d.ts.map +1 -1
  7. package/build/context.js +2 -0
  8. package/build/context.js.map +1 -1
  9. package/build/exports.d.ts +1 -0
  10. package/build/exports.d.ts.map +1 -1
  11. package/build/i18n/auth-be.json +32 -0
  12. package/build/i18n/auth-de.json +32 -0
  13. package/build/i18n/auth-en.json +32 -0
  14. package/build/i18n/auth-es.json +32 -0
  15. package/build/i18n/auth-pl.json +32 -0
  16. package/build/i18n/auth-ru.json +32 -0
  17. package/build/i18n/auth-uk.json +32 -0
  18. package/build/index.d.ts +1 -0
  19. package/build/index.d.ts.map +1 -1
  20. package/build/index.js +1 -0
  21. package/build/index.js.map +1 -1
  22. package/build/login/consts.d.ts +11 -0
  23. package/build/login/consts.d.ts.map +1 -0
  24. package/build/login/consts.js +11 -0
  25. package/build/login/consts.js.map +1 -0
  26. package/build/login/index.d.ts +8 -0
  27. package/build/login/index.d.ts.map +1 -0
  28. package/build/login/index.js +8 -0
  29. package/build/login/index.js.map +1 -0
  30. package/build/login/pump.d.ts +20 -0
  31. package/build/login/pump.d.ts.map +1 -0
  32. package/build/login/pump.js +46 -0
  33. package/build/login/pump.js.map +1 -0
  34. package/build/login/redirect.d.ts +9 -0
  35. package/build/login/redirect.d.ts.map +1 -0
  36. package/build/login/redirect.js +47 -0
  37. package/build/login/redirect.js.map +1 -0
  38. package/build/login/screen.d.ts +15 -0
  39. package/build/login/screen.d.ts.map +1 -0
  40. package/build/login/screen.js +97 -0
  41. package/build/login/screen.js.map +1 -0
  42. package/build/login/service.d.ts +10 -0
  43. package/build/login/service.d.ts.map +1 -0
  44. package/build/login/service.js +17 -0
  45. package/build/login/service.js.map +1 -0
  46. package/build/login/surrogate.d.ts +21 -0
  47. package/build/login/surrogate.d.ts.map +1 -0
  48. package/build/login/surrogate.js +144 -0
  49. package/build/login/surrogate.js.map +1 -0
  50. package/build/login/view.d.ts +26 -0
  51. package/build/login/view.d.ts.map +1 -0
  52. package/build/login/view.js +73 -0
  53. package/build/login/view.js.map +1 -0
  54. package/build/main.d.ts +9 -1
  55. package/build/main.d.ts.map +1 -1
  56. package/build/main.js +9 -1
  57. package/build/main.js.map +1 -1
  58. package/build/modules.d.ts.map +1 -1
  59. package/build/modules.js +11 -1
  60. package/build/modules.js.map +1 -1
  61. package/build/types.d.ts +2 -1
  62. package/build/types.d.ts.map +1 -1
  63. package/package.json +17 -17
  64. package/src/components/dispatcher/component.tsx +72 -8
  65. package/src/context.ts +2 -0
  66. package/src/exports.ts +1 -0
  67. package/src/i18n/auth-be.json +32 -0
  68. package/src/i18n/auth-de.json +32 -0
  69. package/src/i18n/auth-en.json +32 -0
  70. package/src/i18n/auth-es.json +32 -0
  71. package/src/i18n/auth-pl.json +32 -0
  72. package/src/i18n/auth-ru.json +32 -0
  73. package/src/i18n/auth-uk.json +32 -0
  74. package/src/index.ts +1 -0
  75. package/src/login/consts.ts +12 -0
  76. package/src/login/index.ts +7 -0
  77. package/src/login/pump.ts +53 -0
  78. package/src/login/redirect.ts +59 -0
  79. package/src/login/screen.tsx +119 -0
  80. package/src/login/service.ts +19 -0
  81. package/src/login/surrogate.ts +175 -0
  82. package/src/login/view.tsx +94 -0
  83. package/src/main.tsx +11 -2
  84. package/src/modules.ts +12 -1
  85. package/src/types.ts +2 -1
@@ -0,0 +1,59 @@
1
+ import { revokeToken, LoginOutcome } from '@owlmeans/client-auth/login'
2
+ import type { LoginContext, LoginPlugin } from '@owlmeans/client-auth/login'
3
+ import { REDIRECT_LOGIN } from './consts.js'
4
+
5
+ /**
6
+ * The ordinary login flow: this document leaves for the identity provider and comes back.
7
+ *
8
+ * The default plugin, matching everything, so any environment that does not need special handling
9
+ * behaves exactly as it always did.
10
+ */
11
+ export const makeRedirectLoginPlugin = (): LoginPlugin => ({
12
+ alias: REDIRECT_LOGIN,
13
+ priority: 0,
14
+ mode: 'redirect',
15
+ match: () => true,
16
+
17
+ begin: async (_ctx, request) => {
18
+ // Prefer the in-app continuation the caller handed over: a client-side navigation to the
19
+ // dispatcher keeps the app mounted, where a full page load would tear it down and rebuild it.
20
+ if (request.navigate != null) {
21
+ await request.navigate()
22
+
23
+ return LoginOutcome.Handled
24
+ }
25
+ window.location.href = request.url
26
+
27
+ return LoginOutcome.Redirected
28
+ },
29
+
30
+ authorize: async (_ctx, url) => {
31
+ window.location.href = url
32
+
33
+ return LoginOutcome.Redirected
34
+ },
35
+
36
+ // Nothing to hand anywhere — the token was issued in the document that will use it.
37
+ complete: async () => LoginOutcome.Passed,
38
+
39
+ // `resume` is deliberately NOT implemented. The host defaults to `Passed`, which is "keep the
40
+ // session you already have and carry on" — byte for byte what an ordinary tab has always done.
41
+ // Implementing it here would be the one way to regress every unframed application.
42
+
43
+ logout: (ctx, request) => revokeToken(ctx as LoginContext).then(async () => {
44
+ if (request.navigate != null) {
45
+ await request.navigate()
46
+
47
+ return LoginOutcome.Handled
48
+ }
49
+ // A reload rather than a client-side navigation: `useOwlAuth` and its kin read through
50
+ // cached values, so the honest way to make a whole application forget a session is to
51
+ // rebuild it. This is what `useLogout` did inline before the mechanic became a plugin.
52
+ window.location.reload()
53
+
54
+ return LoginOutcome.Handled
55
+ }),
56
+
57
+ // Nothing to tell anyone — the session was cleared in the document that owned it.
58
+ logoutComplete: async () => LoginOutcome.Passed,
59
+ })
@@ -0,0 +1,119 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+ import type { FC } from 'react'
3
+ import { useContext } from '@owlmeans/client'
4
+ import { useI18nLib } from '@owlmeans/client-i18n'
5
+ import {
6
+ LoginIntent, LoginOutcome, LOGIN_INTENT_QUERY, LOGIN_METHOD_QUERY, LOGIN_NEXT_QUERY,
7
+ } from '@owlmeans/client-auth/login'
8
+ import type { LoginService } from '@owlmeans/client-auth/login'
9
+ import type { AppContext } from '../types.js'
10
+ import { LoginSurrogateView, SurrogateStage } from './view.js'
11
+
12
+ /**
13
+ * The login window an embedded application opens one level up.
14
+ *
15
+ * It is NOT wrapped in `DispatcherHOC`, and that is the point: the HOC's continuation navigates to
16
+ * `HOME` when it has nothing else to do, which is how a popup ended up rendering the whole
17
+ * application, with its navigation, inside itself. This screen has no continuation at all — it
18
+ * either hands something back and closes, or it says what it is waiting for.
19
+ *
20
+ * It also never runs the authorization machine. When there is already a session here, that is the
21
+ * answer, and it goes back to the opener immediately — no provider round trip, no PKCE exchange.
22
+ * When there is not, it forwards to the dispatcher (`next`), which owns that flow.
23
+ */
24
+ export const SurrogateScreen: FC = () => {
25
+ const context = useContext() as unknown as AppContext
26
+ const [query] = context.router().useSearchParams()
27
+ const t = useI18nLib('auth')
28
+
29
+ const intent = query.get(LOGIN_INTENT_QUERY) === LoginIntent.Logout
30
+ ? LoginIntent.Logout
31
+ : LoginIntent.Login
32
+
33
+ const [stage, setStage] = useState<SurrogateStage>(SurrogateStage.Working)
34
+ const [error, setError] = useState<string | undefined>()
35
+
36
+ const onAction = useCallback(() => {
37
+ if (stage === SurrogateStage.Standalone) {
38
+ window.location.href = '/'
39
+ return
40
+ }
41
+ if (stage === SurrogateStage.Gesture) {
42
+ const next = query.get(LOGIN_NEXT_QUERY)
43
+ void context.login().begin({ url: next ?? window.location.href })
44
+ return
45
+ }
46
+ window.close()
47
+ }, [context, stage, query])
48
+
49
+ useEffect(() => {
50
+ const login = context.service<LoginService>('login-service')
51
+ // First statement, unconditionally: `markSurrogate` reads `window.name`, and the browser
52
+ // clears that the moment this window's top-level context goes cross-origin. Recording it
53
+ // later means recording nothing.
54
+ login.enter()
55
+
56
+ const env = login.env()
57
+ if (!env.surrogate) {
58
+ // Somebody opened this address directly, or the window lost its marker. Never navigate on
59
+ // its behalf — offer a link and stop.
60
+ setStage(env.embedded ? SurrogateStage.Gesture : SurrogateStage.Standalone)
61
+ return
62
+ }
63
+
64
+ const run = async (): Promise<void> => {
65
+ const token = await context.auth().authenticated()
66
+
67
+ if (intent === LoginIntent.Logout) {
68
+ // Revoked FIRST, before anything can be awaited on a channel that may never answer: a
69
+ // window the user closes half a second later must still have ended the session it opened
70
+ // to end.
71
+ await login.revoke()
72
+ const outcome = await login.logoutComplete()
73
+ setStage(
74
+ outcome === LoginOutcome.Handled ? SurrogateStage.Handing
75
+ : outcome === LoginOutcome.Orphaned ? SurrogateStage.Orphaned
76
+ : SurrogateStage.Failed
77
+ )
78
+ return
79
+ }
80
+
81
+ if (token != null && token !== '') {
82
+ // Already signed in here. The framed application is the one that asked, so the session
83
+ // goes to it rather than being displayed to this window.
84
+ const outcome = await login.resume(token)
85
+ setStage(
86
+ outcome === LoginOutcome.Handled ? SurrogateStage.Handing
87
+ : outcome === LoginOutcome.Orphaned ? SurrogateStage.Orphaned
88
+ : SurrogateStage.Failed
89
+ )
90
+ return
91
+ }
92
+
93
+ // Nothing here yet — the dispatcher owns the authorization round trip, and the provider's
94
+ // callback lands there rather than on this route. The method the user already chose travels
95
+ // with it, so the dispatcher does not ask a second time in a window with no one to ask.
96
+ const next = query.get(LOGIN_NEXT_QUERY)
97
+ if (next == null || next === '') {
98
+ setStage(SurrogateStage.Gesture)
99
+ return
100
+ }
101
+ const method = query.get(LOGIN_METHOD_QUERY)
102
+ const target = method != null && method !== ''
103
+ ? `${next}${next.includes('?') ? '&' : '?'}${LOGIN_METHOD_QUERY}=${encodeURIComponent(method)}`
104
+ : next
105
+ window.location.href = target
106
+ }
107
+
108
+ void run().catch((e: Error) => {
109
+ console.error(e)
110
+ setError(e.message)
111
+ setStage(SurrogateStage.Failed)
112
+ })
113
+ }, [context, intent])
114
+
115
+ return <LoginSurrogateView
116
+ stage={stage} intent={intent} onAction={onAction} error={error}
117
+ translate={(key, defaultValue) => t(key, { defaultValue })}
118
+ />
119
+ }
@@ -0,0 +1,19 @@
1
+ import { appendLogin } from '@owlmeans/client-auth/login'
2
+ import type { BasicConfig, BasicContext } from '@owlmeans/context'
3
+ import { makeRedirectLoginPlugin } from './redirect.js'
4
+ import { makeSurrogateLoginPlugin } from './surrogate.js'
5
+
6
+ /**
7
+ * Register the login host and the two browser flows on a context.
8
+ *
9
+ * Called by `makeContext`, so every web app has working login — including a framed one — without
10
+ * registering anything. An app that needs a different mechanic registers its own plugin at a
11
+ * higher priority; it does not replace this.
12
+ */
13
+ export const appendWebLogin = <C extends BasicConfig, T extends BasicContext<C>>(ctx: T): T => {
14
+ const service = appendLogin<C, T>(ctx).login()
15
+ service.registerPlugin(makeRedirectLoginPlugin())
16
+ service.registerPlugin(makeSurrogateLoginPlugin())
17
+
18
+ return ctx
19
+ }
@@ -0,0 +1,175 @@
1
+ import {
2
+ adoptToken, clearSurrogate, markSurrogate, revokeToken, surrogatePath, LoginIntent, LoginOutcome,
3
+ LOGIN_LOGOUT_MESSAGE, LOGIN_SURROGATE_FEATURES, LOGIN_SURROGATE_NAME, LOGIN_TOKEN_MESSAGE,
4
+ } from '@owlmeans/client-auth/login'
5
+ import type { LoginContext, LoginEnv, LoginPlugin } from '@owlmeans/client-auth/login'
6
+ import { SURROGATE_LOGIN, SURROGATE_LOGIN_PRIORITY } from './consts.js'
7
+ import { awaitSurrogate } from './pump.js'
8
+
9
+ /**
10
+ * Login for a document that cannot complete the flow where it is.
11
+ *
12
+ * An app embedded in a frame cannot redirect to an identity provider: the provider refuses to be
13
+ * embedded (`frame-ancestors`), and its session cookies are third-party there. So the flow runs
14
+ * one window up, in a surrogate window that is top-level and first-party on this application's own
15
+ * origin — where the very same flow completes normally — and the token is passed back to the
16
+ * document that asked for it.
17
+ *
18
+ * This plugin is deliberately not OIDC-specific. The mechanic is "run the login route one window
19
+ * up and hand the token back", and the adoption is the plain auth service, so any relying party
20
+ * that renders a login route gets it by registering nothing.
21
+ *
22
+ * `match` covers BOTH halves of the lifecycle — the framed opener and the surrogate itself, where
23
+ * `embedded` is false. Inside the surrogate the redirect plugin must not win: that window IS
24
+ * top-level, so it authorizes by an ordinary redirect and differs only in what it does with the
25
+ * token at the end.
26
+ */
27
+ export const makeSurrogateLoginPlugin = (): LoginPlugin => {
28
+ /**
29
+ * Give the token to whoever is entitled to it, and get out of the way.
30
+ *
31
+ * Shared by `complete` (a token was just issued here) and `resume` (one was already here),
32
+ * because what happens to it is the same in both cases and only the question differs.
33
+ */
34
+ const handBack = async (token: string, env: LoginEnv): Promise<LoginOutcome> => {
35
+ if (!env.surrogate) {
36
+ // This document started the flow and finished it in place — it already has what it needs.
37
+ return LoginOutcome.Passed
38
+ }
39
+ if (!env.hasOpener) {
40
+ // Authenticated with nowhere to send it. `Cross-Origin-Opener-Policy: same-origin` from the
41
+ // provider severs `window.opener` permanently, so this is not a timing problem to retry.
42
+ return LoginOutcome.Orphaned
43
+ }
44
+
45
+ clearSurrogate()
46
+ // Both windows are the same origin (the surrogate is this application's own login route), so
47
+ // the origin is pinned rather than passed as `*` — the message carries a bearer token.
48
+ window.opener.postMessage({ type: LOGIN_TOKEN_MESSAGE, token }, window.location.origin)
49
+ window.close()
50
+
51
+ return LoginOutcome.Handled
52
+ }
53
+
54
+ const plugin: LoginPlugin = {
55
+ alias: SURROGATE_LOGIN,
56
+ priority: SURROGATE_LOGIN_PRIORITY,
57
+ mode: 'surrogate',
58
+ match: env => env.hasWindow && (env.embedded || env.surrogate),
59
+
60
+ enter: () => { markSurrogate() },
61
+
62
+ begin: (ctx, request, env) => {
63
+ // Already one window up — nothing to open, just run the flow.
64
+ if (env.surrogate) {
65
+ window.location.href = request.url
66
+
67
+ return Promise.resolve(LoginOutcome.Redirected)
68
+ }
69
+
70
+ // Opened FIRST and synchronously: `window.open` escapes the popup blocker only while the
71
+ // user gesture is still being handled, so nothing may be awaited before this line. That is
72
+ // why this function is not `async`.
73
+ //
74
+ // The window opens on the surrogate route rather than on the dispatcher, so its very first
75
+ // paint is a bare "signing you in" panel instead of the application with its navigation. The
76
+ // dispatcher address travels as `next`, because the provider's callback still lands there and
77
+ // whatever flow parameters the caller's URL carried must survive the hop.
78
+ const path = surrogatePath(ctx as LoginContext, {
79
+ intent: LoginIntent.Login, next: request.url,
80
+ })
81
+ const surrogate = window.open(
82
+ path ?? request.url, LOGIN_SURROGATE_NAME, LOGIN_SURROGATE_FEATURES
83
+ )
84
+ if (surrogate == null) {
85
+ return Promise.resolve(LoginOutcome.Failed)
86
+ }
87
+
88
+ return awaitSurrogate(surrogate, LOGIN_TOKEN_MESSAGE, async data => {
89
+ if (data.token == null || data.token === '') {
90
+ return LoginOutcome.Failed
91
+ }
92
+ await adoptToken(ctx as LoginContext, data.token)
93
+ // Adopting the token is not the end of the flow — running the caller's continuation is,
94
+ // exactly as the redirect plugin does before it reports `Handled`. Without it the token
95
+ // lands in the auth service and nothing else happens: the framed app keeps rendering its
96
+ // signed-out tree, and the user watches the login window close over a preview that never
97
+ // changes. `Handled` promises the caller there is nothing left to do.
98
+ await request.navigate?.()
99
+
100
+ return LoginOutcome.Handled
101
+ })
102
+ },
103
+
104
+ authorize: async (_ctx, url, env) => {
105
+ // The surrogate is top-level, so it redirects like any ordinary tab.
106
+ if (env.surrogate) {
107
+ window.location.href = url
108
+
109
+ return LoginOutcome.Redirected
110
+ }
111
+
112
+ // Framed, and not yet one window up. A redirect from here would land in the frame and be
113
+ // refused, and the window that would fix it cannot be opened without a user gesture — so the
114
+ // caller is told to render a control rather than to navigate.
115
+ return LoginOutcome.Gesture
116
+ },
117
+
118
+ complete: async (_ctx, token, env) => await handBack(token, env),
119
+
120
+ // A session that was already here is worth exactly as much as one just issued — to the window
121
+ // that asked for it. Without this the surrogate would render the signed-in application to
122
+ // itself and the framed app would stay signed out, which is the whole reported defect.
123
+ resume: async (_ctx, token, env) => await handBack(token, env),
124
+
125
+ logout: (ctx, request, env) => {
126
+ // Already one window up — end the session here and tell the opener.
127
+ if (env.surrogate) {
128
+ return revokeToken(ctx as LoginContext)
129
+ .then(async () => await plugin.logoutComplete!(ctx, env))
130
+ }
131
+
132
+ const path = surrogatePath(ctx as LoginContext, { intent: LoginIntent.Logout })
133
+ // Opened first and synchronously, for the same reason `begin` does.
134
+ const surrogate = path != null
135
+ ? window.open(path, LOGIN_SURROGATE_NAME, LOGIN_SURROGATE_FEATURES)
136
+ : null
137
+
138
+ // The local session goes next, and UNCONDITIONALLY. A blocked window, a severed opener or a
139
+ // user who closes the popup must never leave THIS document signed in: a logout that only
140
+ // half happened is bad, and one that did not happen at all is worse.
141
+ const local = revokeToken(ctx as LoginContext)
142
+ if (surrogate == null) {
143
+ return local.then(async () => {
144
+ await request.navigate?.()
145
+
146
+ return LoginOutcome.Failed
147
+ })
148
+ }
149
+
150
+ return local.then(async () => await awaitSurrogate(
151
+ surrogate, LOGIN_LOGOUT_MESSAGE, async () => {
152
+ await request.navigate?.()
153
+
154
+ return LoginOutcome.Handled
155
+ }
156
+ ))
157
+ },
158
+
159
+ logoutComplete: async (_ctx, env) => {
160
+ if (!env.surrogate) {
161
+ return LoginOutcome.Passed
162
+ }
163
+ if (!env.hasOpener) {
164
+ return LoginOutcome.Orphaned
165
+ }
166
+ clearSurrogate()
167
+ window.opener.postMessage({ type: LOGIN_LOGOUT_MESSAGE, ok: true }, window.location.origin)
168
+ window.close()
169
+
170
+ return LoginOutcome.Handled
171
+ },
172
+ }
173
+
174
+ return plugin
175
+ }
@@ -0,0 +1,94 @@
1
+ import type { CSSProperties, FC } from 'react'
2
+ import { LoginIntent } from '@owlmeans/client-auth/login'
3
+
4
+ /** What the surrogate window is doing, from the point of view of the person watching it. */
5
+ export enum SurrogateStage {
6
+ /** Working. No control — there is nothing for the user to do but wait. */
7
+ Working = 'working',
8
+ /** Needs a click: the flow cannot continue without a fresh gesture. */
9
+ Gesture = 'gesture',
10
+ /** Done here; handing the result back and closing. */
11
+ Handing = 'handing',
12
+ /** Acted, but with no channel back to the window that asked. */
13
+ Orphaned = 'orphaned',
14
+ /** Ended with nothing. */
15
+ Failed = 'failed',
16
+ /** Not a surrogate at all — someone opened this address directly. */
17
+ Standalone = 'standalone',
18
+ }
19
+
20
+ export interface SurrogateViewProps {
21
+ stage: SurrogateStage
22
+ intent: LoginIntent
23
+ onAction?: () => void
24
+ error?: string
25
+ translate?: (key: string, defaultValue: string) => string
26
+ }
27
+
28
+ /**
29
+ * The whole of what a login window shows.
30
+ *
31
+ * Plain elements and inline styles on purpose. This renders in a popup opened by a `web-panel` app,
32
+ * a `mui-panel` app and a generated Tailwind app alike, and none of their stylesheets is loaded
33
+ * here — a class name would simply do nothing. It is also the reason this component carries no
34
+ * dependency on a UI family at all.
35
+ */
36
+ const box: CSSProperties = {
37
+ maxWidth: '22rem', margin: '15vh auto', padding: '1.5rem', textAlign: 'center',
38
+ fontFamily: 'system-ui, sans-serif', lineHeight: 1.5,
39
+ }
40
+
41
+ const action: CSSProperties = {
42
+ marginTop: '1rem', padding: '.625rem 1.25rem', fontSize: '1rem',
43
+ cursor: 'pointer', borderRadius: '.375rem', border: '1px solid currentColor',
44
+ }
45
+
46
+ const COPY: Record<SurrogateStage, { key: string, en: string, action?: [string, string] }> = {
47
+ [SurrogateStage.Working]: { key: 'working', en: 'Signing you in…' },
48
+ [SurrogateStage.Gesture]: {
49
+ key: 'gesture.title', en: 'Continue to sign in.', action: ['gesture.action', 'Sign in'],
50
+ },
51
+ [SurrogateStage.Handing]: { key: 'handing', en: 'Done. Returning to the application…' },
52
+ [SurrogateStage.Orphaned]: {
53
+ key: 'orphaned', en: 'Signed in. You can close this window and continue in the application.',
54
+ action: ['close', 'Close'],
55
+ },
56
+ [SurrogateStage.Failed]: {
57
+ key: 'failed', en: 'That did not complete. You can close this window and try again.',
58
+ action: ['close', 'Close'],
59
+ },
60
+ [SurrogateStage.Standalone]: {
61
+ key: 'standalone.title', en: 'This page is used to sign in from another window.',
62
+ action: ['standalone.action', 'Open the application'],
63
+ },
64
+ }
65
+
66
+ const LOGOUT_COPY: Partial<Record<SurrogateStage, { key: string, en: string }>> = {
67
+ [SurrogateStage.Working]: { key: 'working', en: 'Signing you out…' },
68
+ [SurrogateStage.Gesture]: { key: 'gesture.title', en: 'Continue to sign out.' },
69
+ [SurrogateStage.Handing]: { key: 'handing', en: 'Signed out. Returning to the application…' },
70
+ [SurrogateStage.Orphaned]: {
71
+ key: 'orphaned', en: 'Signed out. You can close this window.',
72
+ },
73
+ [SurrogateStage.Failed]: {
74
+ key: 'failed', en: 'Sign-out did not complete here. You can close this window.',
75
+ },
76
+ }
77
+
78
+ export const LoginSurrogateView: FC<SurrogateViewProps> = (
79
+ { stage, intent, onAction, error, translate }
80
+ ) => {
81
+ const t = translate ?? ((_key: string, defaultValue: string) => defaultValue)
82
+ const scope = intent === LoginIntent.Logout ? 'logout' : 'login'
83
+ const base = COPY[stage]
84
+ const copy = (intent === LoginIntent.Logout ? LOGOUT_COPY[stage] : undefined) ?? base
85
+
86
+ return <div style={box} data-surrogate-stage={stage} data-surrogate-intent={intent}>
87
+ <p>{t(`surrogate.${scope}.${copy.key}`, copy.en)}</p>
88
+ {error != null && error !== '' &&
89
+ <p style={{ color: '#b00', fontSize: '.875rem' }} role="alert">{error}</p>}
90
+ {base.action != null && onAction != null && <button type="button" style={action} onClick={onAction}>
91
+ {t(`surrogate.${scope}.${base.action[0]}`, base.action[1])}
92
+ </button>}
93
+ </div>
94
+ }
package/src/main.tsx CHANGED
@@ -25,5 +25,14 @@ export const render = (node: ReactNode, opts?: RenderOptions) => {
25
25
  opts?.onReady ?? true ? window.addEventListener('DOMContentLoaded', _callback) : _callback()
26
26
  }
27
27
 
28
- export const renderApp = <C extends AppConfig, T extends AppContext<C>>(context: T, opts?: RenderOptions) =>
29
- render(<WebApp context={context} />, opts)
28
+ /**
29
+ * Mount the application.
30
+ *
31
+ * `children` are rendered inside the context provider and BEFORE the router, which makes them the
32
+ * app's global overlay slot: a consent dialog, a toast surface, anything that must exist on every
33
+ * route and outlive navigation. A component mounted inside a route instead is torn down and
34
+ * rebuilt on every navigation, which for a dialog means it closes itself.
35
+ */
36
+ export const renderApp = <C extends AppConfig, T extends AppContext<C>>(
37
+ context: T, opts?: RenderOptions, children?: ReactNode
38
+ ) => render(<WebApp context={context}>{children}</WebApp>, opts)
package/src/modules.ts CHANGED
@@ -1,9 +1,20 @@
1
- import { DISPATCHER } from '@owlmeans/auth'
1
+ import { DISPATCHER, DISPATCHER_SURROGATE } from '@owlmeans/auth'
2
2
  import { modules as list } from '@owlmeans/client-auth'
3
3
  import { elevate } from '@owlmeans/client-entrypoint'
4
4
  import { handler } from '@owlmeans/client'
5
5
  import { Dispatcher } from './components/dispatcher/component.js'
6
+ import { SurrogateScreen } from './login/screen.js'
6
7
 
7
8
  elevate(list, DISPATCHER, handler(Dispatcher), { force: true })
8
9
 
10
+ /**
11
+ * Elevated here rather than in a relying-party package on purpose.
12
+ *
13
+ * The surrogate mechanic is not OIDC-specific — it is "run the login route one window up and hand
14
+ * the result back" — and every web application already spreads this list. Putting the screen here
15
+ * means `web-panel`, `mui-panel` and every generated target gain a working login window with no
16
+ * edit of their own, which is the only way an application that is already deployed can get it.
17
+ */
18
+ elevate(list, DISPATCHER_SURROGATE, handler(SurrogateScreen))
19
+
9
20
  export const modules = list
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { AuthServiceAppend } from '@owlmeans/client-auth'
2
+ import type { LoginServiceAppend } from '@owlmeans/client-auth/login'
2
3
  import type { ClientConfig } from '@owlmeans/client-context'
3
4
  import type { ClientContext } from '@owlmeans/client'
4
5
 
@@ -13,5 +14,5 @@ export interface AppConfig extends ClientConfig {
13
14
  }
14
15
 
15
16
  export interface AppContext<C extends AppConfig = AppConfig> extends ClientContext<C>,
16
- AuthServiceAppend {
17
+ AuthServiceAppend, LoginServiceAppend {
17
18
  }