@owlmeans/client-iam 0.1.18-rc.64 → 0.1.18-rc.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,173 @@
1
+ # @owlmeans/client-iam
2
+
3
+ The browser half of the OwlMeans IAM in one import, for a web app that signs its people in through
4
+ an OwlMeans OIDC provider. `appendIam` wires the OIDC relying-party guard and puts a consent
5
+ precondition in front of every sign-in; the package also re-exports the sign-in surface
6
+ (`useLogin`, `useLogout`, `withIamGuard`, `iamEntrypoints`), lists the session's organizations and
7
+ switches between them, and re-exports `hasPermission` for showing or hiding a control. It decides
8
+ nothing: permissions are enforced by the app's server (`@owlmeans/server-iam`). It is browser-only
9
+ (it depends on `@owlmeans/web-client` and `@owlmeans/web-oidc-rp`); server code uses
10
+ `@owlmeans/server-iam` and the shared permission model lives in `@owlmeans/iam`.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ bun add @owlmeans/client-iam@^0.1.18-rc.65
16
+ ```
17
+
18
+ ## Concepts
19
+
20
+ - **Relying-party guard** — `appendOidcGuard` from `@owlmeans/web-oidc-rp`, installed by
21
+ `appendIam`. The provider list is read from `cfg.oidc.providers`.
22
+ - **Consent precondition** — a `LoginService` precondition (`'consent-before-login'`, priority 100)
23
+ that refuses to start a sign-in until the essential consent category is granted, and opens the
24
+ consent dialog in the same gesture.
25
+ - **Acting organization** — the session acts in one organization entity at a time. That is session
26
+ state held by the app's server, moved with `switchOrganization(entitySlug)`, never a request
27
+ parameter.
28
+ - **Organization item** — `OidcOrganizationItem`: `{ entitySlug, title?, owner, groups?, home?, acting }`.
29
+ - **Permission check** — `hasPermission` runs the same check the server gate runs; in a screen it
30
+ only decides whether a control is visible.
31
+
32
+ ## Usage
33
+
34
+ ### Wire sign-in into a web app
35
+
36
+ ```typescript
37
+ import { bindAll } from '@owlmeans/client-entrypoint'
38
+ import { appendIam, iamEntrypoints, withIamGuard } from '@owlmeans/client-iam'
39
+
40
+ appendIam(context) // OIDC guard + consent precondition
41
+
42
+ export const protocols = withIamGuard(appProtocols) // decorate the immutable tree once
43
+ export const bindings = [
44
+ ...bindAll(protocols.api),
45
+ ...iamEntrypoints(), // sign-in pair, organization switch, dispatcher
46
+ ]
47
+ ```
48
+
49
+ An app that sets no cookie at all turns the consent precondition off:
50
+
51
+ ```typescript
52
+ appendIam(context, { consent: { disabled: true } })
53
+ ```
54
+
55
+ A context wired without `appendIam` adds the precondition on its own:
56
+
57
+ ```typescript
58
+ import { requireConsentForLogin } from '@owlmeans/client-iam'
59
+
60
+ requireConsentForLogin(context, { category: 'essential' })
61
+ ```
62
+
63
+ ### Sign-in and sign-out controls
64
+
65
+ ```tsx
66
+ import { useLogin, useLogout } from '@owlmeans/client-iam'
67
+
68
+ export const AccountControls = () => {
69
+ const [href, onLogin] = useLogin('/projects') // land on /projects after signing in
70
+ const onLogout = useLogout()
71
+
72
+ return (
73
+ <>
74
+ <a href={href} onClick={onLogin}>Log in</a>
75
+ <button onClick={onLogout}>Log out</button>
76
+ </>
77
+ )
78
+ }
79
+ ```
80
+
81
+ When consent is missing, the sign-in resolves as `LoginOutcome.Gesture` and the consent dialog
82
+ opens; the person presses "Log in" again after accepting, because the redirect or popup must start
83
+ from a real gesture.
84
+
85
+ ### Organizations of the session
86
+
87
+ ```typescript
88
+ import { organizationSwitchOf, ORGANIZATION_REFUSAL } from '@owlmeans/client-iam'
89
+
90
+ const organizations = organizationSwitchOf(context)
91
+ const items = await organizations.listOrganizations() // the acting one has `acting: true`
92
+
93
+ try {
94
+ await organizations.switchOrganization('hiking-club')
95
+ // every later request, and every screen reading `auth`, acts in hiking-club
96
+ } catch (error) {
97
+ // AuthForbidden(ORGANIZATION_REFUSAL): not one of the person's organizations; the token stays
98
+ }
99
+ ```
100
+
101
+ Both calls go to the app's own server behind `OIDC_GUARD`, so they need the bindings
102
+ `iamEntrypoints()` spreads. A successful switch adopts the re-signed token through `adoptToken`
103
+ from `@owlmeans/client-auth/login`.
104
+
105
+ ### Permissions in a screen
106
+
107
+ ```typescript
108
+ import { hasPermission } from '@owlmeans/client-iam'
109
+
110
+ const canApprove = hasPermission(context.auth().user(), 'loan--approve', { resourceId: loanId })
111
+ ```
112
+
113
+ ## API
114
+
115
+ | Symbol | Kind | Purpose |
116
+ |---|---|---|
117
+ | `appendIam(context, opts?)` | function | `appendOidcGuard` plus `requireConsentForLogin`; `opts` is `AppendIamOptions` |
118
+ | `requireConsentForLogin(ctx, opts?)` | function | Registers the consent precondition on the login service |
119
+ | `organizationSwitchOf(ctx)` | function | Memoized `OrganizationSwitchHelper` of a context |
120
+ | `makeOrganizationSwitchHelper(ctx)` | function | Builds an `OrganizationSwitchHelper` (unmemoized) |
121
+ | `listOrganizations(ctx)`, `switchOrganization(ctx, slug)` | function | Deprecated wrappers over `organizationSwitchOf(ctx)` |
122
+ | `withIamGuard(tree, coguards?)` | function | `withOidcGuard` of `@owlmeans/oidc` — decorated copy of a protocol tree |
123
+ | `iamEntrypoints(dispatcherProps?)` | function | `oidcEntrypoints` of `@owlmeans/web-oidc-rp` |
124
+ | `useLogin(target?)` | hook | `[href, onClick]` for a sign-in control |
125
+ | `useLogout(target?)` | hook | `onClick` for a sign-out control |
126
+ | `LoginOutcome`, `LoginIntent` | enum | Re-exported from `@owlmeans/client-auth/login` |
127
+ | `hasPermission(auth, permission, opts?)` | function | Re-exported from `@owlmeans/iam`; `opts` is `{ scope?, resourceId?, entitySlug? }` |
128
+ | `ORGANIZATION_REFUSAL`, `ORGANIZATION_OWNER_REFUSAL` | const | `AuthForbidden` reasons for a non-member and a non-owner |
129
+ | `CONSENT_LOGIN_PRECONDITION` | const | `'consent-before-login'` |
130
+ | `CLIENT_IAM_SERVICE` | const | `'client-iam-service'` — an alias constant nothing registers |
131
+
132
+ ### Types
133
+
134
+ | Symbol | Purpose |
135
+ |---|---|
136
+ | `AppendIamOptions` | `{ consent?: ConsentLoginOptions }` |
137
+ | `ConsentLoginOptions` | `{ category?: string, disabled?: boolean }`; `category` defaults to `essential` |
138
+ | `OrganizationSwitchHelper` | `{ listOrganizations(), switchOrganization(entitySlug) }` |
139
+ | `OidcOrganizationItem` | One organization of the session |
140
+ | `LoginPlugin`, `LoginRequest`, `LogoutRequest`, `LoginService`, `LoginPrecondition`, `LoginMethod`, `LoginMethodSource`, `LoginScreenProps` | Re-exported from `@owlmeans/client-auth/login` |
141
+ | every `@owlmeans/iam` type | Re-exported with `export type *` |
142
+
143
+ ## Common pitfalls
144
+
145
+ - Decorate the protocol tree with `withIamGuard` before binding it; the helpers never append
146
+ declarations to an already flattened entrypoint list.
147
+ - Organization calls fail without the `iamEntrypoints()` bindings.
148
+ - Never write `auth` or the stored token by hand after a switch — `switchOrganization` already adopts
149
+ the re-signed token; re-read `auth` afterwards.
150
+ - Organizations travel by `entitySlug` only; never send an organization's `entityId` from the
151
+ browser.
152
+ - `ORGANIZATION_REFUSAL` / `ORGANIZATION_OWNER_REFUSAL` are reasons, not messages — phrase them for
153
+ the person.
154
+ - `hasPermission` in a screen hides or shows a control; the server gate is the decision.
155
+ - A client without the provider's `organizations` scope lists no organizations and refuses every
156
+ switch.
157
+
158
+ The `client-iam` skill covers this package; `login-plugins`, `web-oidc-rp` and `server-iam` cover
159
+ the machinery underneath and the server side.
160
+
161
+ ## Related packages
162
+
163
+ - [`@owlmeans/web-oidc-rp`](../web-oidc-rp) — the OIDC guard, bindings and dispatcher
164
+ - [`@owlmeans/oidc`](../oidc) — shared OIDC protocols, `withOidcGuard`, organization types
165
+ - [`@owlmeans/client-auth`](../client-auth) — login service, plugins and `adoptToken`
166
+ - [`@owlmeans/consent`](../consent) — the consent store the precondition reads
167
+ - [`@owlmeans/web-consent`](../web-consent) — the consent dialog the precondition opens
168
+ - [`@owlmeans/iam`](../iam) — the permission model and `hasPermission`
169
+ - [`@owlmeans/server-iam`](../server-iam) — the server gate and organization management
170
+
1
171
  <!-- owlmeans:agent-guidance:start -->
2
172
  ## Agent guidance
3
173
 
@@ -6,7 +176,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
6
176
  your project's skill store (`.agents/skills/`):
7
177
 
8
178
  ```sh
9
- npx @owlmeans/agent-skills@^0.1.18-rc.51
179
+ npx @owlmeans/agent-skills@^0.1.18-rc.52
10
180
  ```
11
181
 
12
182
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/client-iam",
4
- "version": "0.1.18-rc.64",
5
- "generatedAt": "2026-10-06T11:45:57.675Z",
4
+ "version": "0.1.18-rc.65",
5
+ "generatedAt": "2026-10-08T21:27:54.312Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/client-iam
9
9
 
10
10
  **Layer:** Client (browser-only — it depends on `@owlmeans/web-client` and `@owlmeans/web-oidc-rp`)
11
- **Install:** `"@owlmeans/client-iam": "^0.1.18-rc.64"` in `dependencies`
11
+ **Install:** `"@owlmeans/client-iam": "^0.1.18-rc.65"` in `dependencies`
12
12
 
13
13
  The browser side of the IAM for an application that signs its people in through an OwlMeans OIDC
14
14
  provider. One import wires the relying party, puts the consent precondition in front of every
@@ -54,8 +54,10 @@ flattened entrypoint list.
54
54
 
55
55
  The consent precondition sits on `LoginService.begin`, the one funnel every sign-in mechanic passes
56
56
  through and the place the user's gesture is still live: a refusal resolves as
57
- `LoginOutcome.Gesture` and opens the consent dialog in the same gesture, and the person presses
58
- "Log in" again after accepting (`login-plugins`, `web-consent`).
57
+ `LoginOutcome.Gesture` and opens the consent preferences window in the same gesture, and the person
58
+ presses "Log in" again after accepting (`login-plugins`, `web-consent`). A visitor decided for
59
+ automatically (located outside the consent countries — the `consent` skill's geo gate) already has a
60
+ record and passes.
59
61
 
60
62
  ## Organizations of the session
61
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/client-iam",
3
- "version": "0.1.18-rc.64",
3
+ "version": "0.1.18-rc.65",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,14 +22,14 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@owlmeans/client-auth": "^0.1.18-rc.59",
26
- "@owlmeans/consent": "^0.1.18-rc.11",
25
+ "@owlmeans/client-auth": "^0.1.18-rc.60",
26
+ "@owlmeans/consent": "^0.1.18-rc.12",
27
27
  "@owlmeans/context": "^0.1.18-rc.34",
28
28
  "@owlmeans/entrypoint": "^0.1.18-rc.41",
29
- "@owlmeans/iam": "^0.1.18-rc.51",
30
- "@owlmeans/oidc": "^0.1.18-rc.56",
31
- "@owlmeans/web-client": "^0.1.18-rc.62",
32
- "@owlmeans/web-oidc-rp": "^0.1.18-rc.65"
29
+ "@owlmeans/iam": "^0.1.18-rc.52",
30
+ "@owlmeans/oidc": "^0.1.18-rc.57",
31
+ "@owlmeans/web-client": "^0.1.18-rc.63",
32
+ "@owlmeans/web-oidc-rp": "^0.1.18-rc.66"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@owlmeans/dep-config": "workspace:*",