@owlmeans/auth 0.1.18-rc.36 → 0.1.18-rc.38
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 +2 -2
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/auth/SKILL.md +6 -4
- package/agent-meta/skills/auth-protocol/SKILL.md +97 -80
- package/build/errors.d.ts +8 -0
- package/build/errors.d.ts.map +1 -1
- package/build/errors.js +8 -0
- package/build/errors.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +9 -1
- package/tests/errors.spec.ts +19 -0
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ shared auth protocols and organization-entity resolution (`entityKeyOf`, `requir
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
bun add @owlmeans/auth@^0.1.18-rc.
|
|
17
|
+
bun add @owlmeans/auth@^0.1.18-rc.38
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
`ajv` is a **peer** dependency — install it alongside, or `verifyAuth` / `verifyAuthCredentials`
|
|
@@ -330,7 +330,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
330
330
|
your project's skill store (`.agents/skills/`):
|
|
331
331
|
|
|
332
332
|
```sh
|
|
333
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
333
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.46
|
|
334
334
|
```
|
|
335
335
|
|
|
336
336
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/auth",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.38",
|
|
5
|
+
"generatedAt": "2026-10-03T11:19:50.769Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/auth
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/auth": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/auth": "^0.1.18-rc.38"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
Types, enums, errors and schemas only — no services, no wiring. Every other auth package builds on
|
|
14
14
|
this vocabulary, so a symbol belongs here exactly when both a server and a browser need to agree on
|
|
@@ -58,7 +58,7 @@ it.
|
|
|
58
58
|
|
|
59
59
|
| Error | Raise it when |
|
|
60
60
|
|-------|---------------|
|
|
61
|
-
| `AuthUnknown` | The thing being authenticated is not known at all — an unregistered plugin type, a request whose auth state is missing |
|
|
61
|
+
| `AuthUnknown` | The thing being authenticated is not known at all — an unregistered plugin type, a method a gate refuses, a request whose auth state is missing. Declares `httpStatus = 400`: the caller's request, never a 500 |
|
|
62
62
|
| `AuthManagerError` | The auth manager itself failed |
|
|
63
63
|
| `AuthManagerUnsupported` | The manager cannot serve this request shape |
|
|
64
64
|
| `AuthenFailed` | Authentication was attempted and rejected (bad challenge, bad code, bad signature) |
|
|
@@ -142,8 +142,10 @@ export const list = handlers<Context>().request(projectProtocols.list, async (re
|
|
|
142
142
|
|
|
143
143
|
Rules of thumb:
|
|
144
144
|
|
|
145
|
-
- A gate that decides "not allowed" throws `AuthForbidden
|
|
146
|
-
on
|
|
145
|
+
- A gate that decides "not allowed" throws `AuthForbidden` (403); a handler that finds no identity
|
|
146
|
+
to act on, or a sign-in naming a method nobody serves, throws `AuthUnknown` (400); a failed
|
|
147
|
+
credential check throws `AuthenFailed`. `@owlmeans/server-api` maps the authorization family to
|
|
148
|
+
401/403 before reading a class's declared `httpStatus`, so `AuthUnknown`'s 400 never masks them.
|
|
147
149
|
- Keep ownership rules out of this package. Downstream apps compose `@owlmeans/entrypoint` gates or
|
|
148
150
|
handler-level checks around these types.
|
|
149
151
|
- WebSocket wiring uses `Auth`, `AuthToken` and `AuthenticationStage` to move a token-bearing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: auth-protocol
|
|
3
|
-
description: Comprehensive reference for the OwlMeans authentication and authorization protocol — the Ed25519, OIDC, provider-backed local identity, email-OTP and PK-supervisor paths, the core types and error hierarchy, guards and gates, the trust resource, the envelope shape, organization-entity resolution, the refresh flow, and the mocking points. Auto-invoked when files under auth*, *oidc*, server-auth-identity, did*, wled or client-payment are touched.
|
|
3
|
+
description: Comprehensive reference for the OwlMeans authentication and authorization protocol — the Ed25519, OIDC, provider-backed local identity, email-OTP, hosted-app (integrated provider) and PK-supervisor paths, the identity model (one account per e-mail, credentials on the account, profile rows per app and organization, organizations with groups), pairwise subjects, the acting organization as session state and its switch, the four permission kinds, the core types and error hierarchy, guards and gates, the trust resource, the envelope shape, organization-entity resolution, the refresh flow, and the mocking points. Auto-invoked when files under auth*, *oidc*, *iam*, server-auth-identity, did*, wled or client-payment are touched.
|
|
4
4
|
---
|
|
5
5
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
6
|
|
|
@@ -30,19 +30,19 @@ Use case: service-to-service, wallet provider, backend clients, high-security br
|
|
|
30
30
|
Use case: browser clients, third-party IdP integration, multi-tenant SaaS.
|
|
31
31
|
|
|
32
32
|
1. Standard OAuth2 authorization-code flow. The relying party redirects to the provider and the return leg exchanges the code: `makeOidcClientService` (`@owlmeans/server-oidc-rp`) replays the stored PKCE verifier and grants the token set.
|
|
33
|
-
2. Server decodes the ID token
|
|
33
|
+
2. Server decodes the ID token — only the id_token; an access token's format is provider-private — builds an `Auth` from its claims, and wraps it in an envelope of type `oidc-wrapped-token` signed with the service key — the bearer is `OIDC-WRAPPED-TOKEN <encoded>`. The token set and, for a tenanted client, the organizations stay in the server-side session record ("Organizations and the session").
|
|
34
34
|
3. Subsequent requests are matched and handled by `makeOidcGuard` (`@owlmeans/oidc`), which verifies the envelope signature against the service key and delegates freshness to the `WRAPPED_OIDC` service.
|
|
35
|
-
4. Refresh: `makeOidcWrappingService` (`@owlmeans/server-oidc-rp`) re-validates the stored token set — introspection, or a refresh grant once `expires_at` has passed — and re-signs the wrapped token. When the value changes, the guard returns it in the **`TOKEN_UPDATE` response header** (`'auth-token-refresh'`, `@owlmeans/auth-common`); an empty value means the session is over. It is a header, not a route: `@owlmeans/server-api` lists it in `exposedHeaders` and `@owlmeans/api`'s client service feeds it back into `AuthService.update()`. Where the deployment has a separate auth manager, the wrapper reaches it over the `external-auth:auth:update` declaration from `makeAuthServiceEntrypoints`, bound at `/<prefix>/auth/update`.
|
|
35
|
+
4. Refresh: `makeOidcWrappingService` (`@owlmeans/server-oidc-rp`) re-validates the stored token set — introspection, or a refresh grant once `expires_at` has passed; current userinfo on every request under `sessionValidation: 'required'` — and re-signs the wrapped token. When the value changes, the guard returns it in the **`TOKEN_UPDATE` response header** (`'auth-token-refresh'`, `@owlmeans/auth-common`); an empty value means the session is over. It is a header, not a route: `@owlmeans/server-api` lists it in `exposedHeaders` and `@owlmeans/api`'s client service feeds it back into `AuthService.update()`. Where the deployment has a separate auth manager, the wrapper reaches it over the `external-auth:auth:update` declaration from `makeAuthServiceEntrypoints`, bound at `/<prefix>/auth/update`.
|
|
36
36
|
|
|
37
|
-
### Provider-
|
|
37
|
+
### Provider-backed local identity
|
|
38
38
|
|
|
39
|
-
Use case:
|
|
39
|
+
Use case: a deployment that signs its own people in through Google, OIDC or an e-mail code and authorizes against its own identity store (`@owlmeans/server-auth-identity`).
|
|
40
40
|
|
|
41
41
|
1. Browser imports `@owlmeans/web-oidc-rp/auth/plugins`, which registers OIDC and Google plugins in `@owlmeans/client-auth`.
|
|
42
42
|
2. The plugin persists auth control state, redirects to the provider, restores state on return, and submits code/query params as `AuthCredentials`.
|
|
43
|
-
3. Server exchanges the provider code through `@owlmeans/server-oidc-rp`
|
|
44
|
-
4.
|
|
45
|
-
5. Server returns a normal OwlMeans bearer token carrying the organization's `entitySlug`. Downstream product gates authorize against
|
|
43
|
+
3. Server exchanges the provider code through `@owlmeans/server-oidc-rp`. The Google plugin refuses a userinfo whose `email_verified` is not `true` (`AuthenFailed('email-verified')`): the address is what links the sign-in to an account.
|
|
44
|
+
4. The linking service (`AUTH_IDENTITY_LINKING`) maps `ProviderProfileDetails` onto the identity model ("The identity model"): `getLinkedProfile` follows the method's credential to its account and answers the row of THIS deployment's app in the account's main organization; otherwise `linkProfile(details, { username: verifiedEmail })` runs `ensureAccount` — a further method of a known address becomes another credential on the same account, a new address registers an account with a personal organization — and `ensureProfile` for the deployment's own app there (`owner: true`, `scopes: ['*']`).
|
|
45
|
+
5. Server returns a normal OwlMeans bearer token carrying the organization's `entitySlug` and the row's `profileId`. Downstream product gates authorize against that row — requiring its `service` to be the deployment's own app, because the same organization holds hosted apps' rows — not against `OIDC_GATE`.
|
|
46
46
|
|
|
47
47
|
### Email one-time code
|
|
48
48
|
|
|
@@ -50,7 +50,19 @@ Use case: passwordless sign-in where no external IdP is wanted.
|
|
|
50
50
|
|
|
51
51
|
1. Client posts `{ type: 'email-otp', userId: <email> }` to `/authentication/init`.
|
|
52
52
|
2. `@owlmeans/server-auth-otp` mails a six-digit code, stores it in Redis under a TTL, and answers with a challenge of `"<email>::<nonce>"` — the nonce is what keeps two independent attempts for one address from colliding in the manager's anti-replay cache.
|
|
53
|
-
3. Client posts the code as `AuthCredentials.credential`; the plugin verifies and consumes it, resolves the identity through `AUTH_IDENTITY_LINKING
|
|
53
|
+
3. Client posts the code as `AuthCredentials.credential`; the plugin verifies and consumes it, resolves the identity through the linking service `cfg.otp.identityAlias` names (default `AUTH_IDENTITY_LINKING`), and the manager signs the credential envelope as usual. An integrated provider's end-user login names the e-mail proof linking service there instead (next path).
|
|
54
|
+
|
|
55
|
+
### Hosted-app sign-in through the integrated provider
|
|
56
|
+
|
|
57
|
+
Use case: an application a deployment hosts (a generated target) signs its end users in against the deployment's own OIDC provider (`@owlmeans/server-oidc-provider` with `@owlmeans/iam-integrated`), over the same identity store.
|
|
58
|
+
|
|
59
|
+
1. The application's server relying party (`appendIam` of `@owlmeans/server-iam`) sends the browser to the provider with the base scopes plus `permissions` (and `organizations` for a tenanted client); a provisioned client's allowlist is a superset of everything a relying party asks for.
|
|
60
|
+
2. The provider's login screen runs the e-mail code against the deployment's auth manager with the e-mail proof linking service (`makeEmailProofLinkingService`). Its payload proves the address and identifies nobody: `profileId: IAM_EMAIL_PROOF` (`'proof:email'`), `userId` = the address, one narrow end-user scope, no `entitySlug` — and it writes nothing.
|
|
61
|
+
3. The provider's interaction finalizer verifies that proof, loads the interaction's client and calls `subjects.signIn(clientId, { email })`: the account (one per address; the e-mail code a credential on it), its primary row of the app as owner of the personal organization, and — for staff of the client's owning organization — the staff row there. The provider grant and session name the ACCOUNT id.
|
|
62
|
+
4. `findAccount` asks `subjects.resolve(clientId, accountId)` for the claims. `null` (no row of the app, a disabled or expired primary row) refuses the account, and the provider's `account_refused` login check sends the browser back to the login screen instead of failing the consent.
|
|
63
|
+
5. The claims: `sub` = the pairwise subject, `email`, `permissions`, and `organizations` under its scope. The account's record id never leaves the provider.
|
|
64
|
+
|
|
65
|
+
**Pairwise subjects.** Every client sees its own subject for one account: `profileIdOf(clientId, accountId)` (`subjects.identify`) — the very `profileId` of the account's rows of that app — the same in the id_token, userinfo and introspection, and different for every other client, so two apps cannot correlate their users. The provider configuration that produces it (pairwise-only, the sector URI, `claims()` answering the account id) is governed by `server-oidc-provider` → "Pairwise subjects".
|
|
54
66
|
|
|
55
67
|
### PK supervisor (development only)
|
|
56
68
|
|
|
@@ -62,56 +74,65 @@ Use case: deterministic end-to-end tests, and operator access to a development o
|
|
|
62
74
|
|
|
63
75
|
Never enabled in real production — see the `supervisor-auth` skill.
|
|
64
76
|
|
|
65
|
-
##
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
- `
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
77
|
+
## The identity model
|
|
78
|
+
|
|
79
|
+
One store (`@owlmeans/server-auth-identity`) serves a deployment's own app and every app it hosts.
|
|
80
|
+
Its records, fields, indexes, races and events are governed by the `server-auth-identity` skill;
|
|
81
|
+
the protocol relies on these rules:
|
|
82
|
+
|
|
83
|
+
- **Account** — the person, ONE per e-mail; `entityId` = its personal organization. Every sign-in
|
|
84
|
+
method (e-mail code, Google, PK supervisor) is a **credential** on the account, never on a row.
|
|
85
|
+
- **Profile row** — one per (account, app, organization); `service` = the app (the deployment's own
|
|
86
|
+
key, or a hosted app's client id); `profileId = profileIdOf(service, accountId)` is computed, the
|
|
87
|
+
same on every row of one (account, app), and is the pairwise subject that app's client sees. The
|
|
88
|
+
PRIMARY row (in the personal organization) carries `home` and `disabled`.
|
|
89
|
+
- **Organization** (`OrgEntity`) — `slug` (the wire `entitySlug`, renameable), `iamKey` (frozen,
|
|
90
|
+
claimed as `entityKey`, server-side only) and the organization's **groups** inside the document.
|
|
91
|
+
- Registration anywhere creates the account, its personal organization and an owner row of the app
|
|
92
|
+
signing in. The address IS the identity: every caller of `ensureAccount` must have verified it.
|
|
93
|
+
|
|
94
|
+
## Organizations and the session
|
|
95
|
+
|
|
96
|
+
Tenancy is a property of the hosted app's client (`IamClientConfig.users` / `.operators`,
|
|
97
|
+
`iam` skill): with neither flag every subject acts in the client's owning organization; with either,
|
|
98
|
+
the client asks for `ORGANIZATIONS_SCOPE` and each subject acts in organizations of its own.
|
|
99
|
+
|
|
100
|
+
- **The acting organization is session state of the relying party**, never a request parameter.
|
|
101
|
+
The exchange picks it, every validation re-picks it by `entityKey`, and only the switch moves it —
|
|
102
|
+
governed by `server-oidc-rp` → "Organizations" (claims, session record, browser-token contents,
|
|
103
|
+
the switch handlers).
|
|
104
|
+
- **The request entity** on such a relying party is `{ id: entityKey, slug, iamKey: entityKey }`,
|
|
105
|
+
attached by the OIDC guard; `requireEntityKey(req)` answers the `entityKey` — the tenant key a
|
|
106
|
+
hosted app stores its records by (`auth-common` → "The organization entity").
|
|
107
|
+
- **Browser**: `listOrganizations` / `switchOrganization` (`client-iam`). **Server**:
|
|
108
|
+
`organizationsOf` / `organizationOf` and the runtime IAM client `iamRuntime` (`server-iam`) over the
|
|
109
|
+
provider's runtime IAM API (`makeIamRuntimeProtocols`, `iam` skill), advertised as the discovery
|
|
110
|
+
field `owlmeans_iam_api`.
|
|
111
|
+
|
|
112
|
+
## Permission kinds
|
|
113
|
+
|
|
114
|
+
What a grant binds to — nothing, an organization (`entityScoped`), resource ids (`resourceScoped`) or
|
|
115
|
+
both — is a property of its DEFINITION, and `defaultClass` (`none` / `user` / `member` / `owner`)
|
|
116
|
+
says who holds it without a grant. `hasPermission(auth, name, { scope?, resourceId?, entitySlug? })`
|
|
117
|
+
is fail-closed on a bound set. The model is governed by the `iam` skill ("Permission kinds",
|
|
118
|
+
"Default classes"); the gate that asserts it by `server-iam` ("How the gate decides").
|
|
119
|
+
|
|
120
|
+
## Types, constants and errors
|
|
121
|
+
|
|
122
|
+
The payload chain is `Authorization` (`entitySlug?`, `scopes`, `permissions?`, …) → `ProfilePayload`
|
|
123
|
+
(+ `groups?`) → `AuthPayload` (+ `type`, `role`, `userId`, `profileId?`, …) → `AuthCredentials`
|
|
124
|
+
(+ `challenge`, `credential`) for authentication and `Auth` (+ `token`, `isUser`, `createdAt`) for a
|
|
125
|
+
resolved identity. **`entitySlug` is the only organization-entity value on the wire**; read it with
|
|
126
|
+
`entitySlugOf(payload)`, never off the field. Where each name is governed:
|
|
127
|
+
|
|
128
|
+
- types, `AuthRole` (a **string** enum), `AuthenticationType`, query/header constants, the error
|
|
129
|
+
hierarchy (`AuthError` root; `AuthUnknown` 400, `AuthorizationError` → `AuthForbidden`,
|
|
130
|
+
`AuthenFailed` …) — the `auth` skill;
|
|
131
|
+
- guard aliases (`DEFAULT_GUARD`, `GUARD_ED25519`), `TOKEN_UPDATE`, reserved paths, `ENTITY_RESOLVER`
|
|
132
|
+
— the `auth-common` skill;
|
|
133
|
+
- `OIDC_GATE`, the Google plugin/service names, the `permissions` / `organizations` scopes and their
|
|
134
|
+
refusal reasons, `IAM_API_METADATA` — the `oidc` skill. An app that uses a provider only to sign in
|
|
135
|
+
and authorizes against local identity declares its own gate alias (`server-oidc-rp` → Rules).
|
|
115
136
|
|
|
116
137
|
## Guard interface
|
|
117
138
|
|
|
@@ -142,10 +163,10 @@ import { TRUSTED } from '@owlmeans/config'
|
|
|
142
163
|
const { user, key } = await trust(context, TRUSTED, context.cfg.alias ?? context.cfg.service)
|
|
143
164
|
```
|
|
144
165
|
|
|
145
|
-
It loads the record by `name` (
|
|
146
|
-
`
|
|
147
|
-
|
|
148
|
-
|
|
166
|
+
It loads the record by `name` (a fourth argument matches another field), throws `SyntaxError` when
|
|
167
|
+
there is none, and answers a signing key pair when the `TrustedRecord` carries a `secret`, a
|
|
168
|
+
verify-only one otherwise. The `TRUSTED` config resource is the source of truth for known signing
|
|
169
|
+
identities — the auth service, peer services, wallet providers, supervisors (`auth-common`).
|
|
149
170
|
|
|
150
171
|
## Envelope shape
|
|
151
172
|
|
|
@@ -165,20 +186,10 @@ It loads the record by `name` (pass a fourth argument to match on another field)
|
|
|
165
186
|
|
|
166
187
|
## Key model
|
|
167
188
|
|
|
168
|
-
`KeyPairModel` (`@owlmeans/basic-keys`)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
sign: (data) => Promise<string>
|
|
173
|
-
verify: (data, signature) => Promise<boolean>
|
|
174
|
-
export: () => string // private, "ed25519:<base64>"
|
|
175
|
-
exportPublic: () => string // public, "ed25519:<base64>"
|
|
176
|
-
exportAddress: () => string
|
|
177
|
-
encrypt / decrypt / dcrpt
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
`makeKeyPairModel(input?)` (`@owlmeans/basic-keys`) accepts a `KeyPair`, an `ed25519:<base64>` string, or `undefined` for random. `fromPubKey(credential)` builds a public-only model. `packAuthCredentials(auth, extra, signer)` signs an `AuthCredentials` for the Ed25519 path.
|
|
189
|
+
`KeyPairModel` (`@owlmeans/basic-keys`, `basic-keys` skill) signs, verifies and exports
|
|
190
|
+
`ed25519:<base64>` keys; `makeKeyPairModel(input?)` builds one, `fromPubKey(credential)` a
|
|
191
|
+
verify-only one, and `packAuthCredentials(auth, extra, signer)` signs an `AuthCredentials` for the
|
|
192
|
+
Ed25519 path.
|
|
182
193
|
|
|
183
194
|
## Setup wiring
|
|
184
195
|
|
|
@@ -186,17 +197,19 @@ Server-side:
|
|
|
186
197
|
- `makeAuthService(alias?)` / `appendAuthService(ctx, alias?)` (`@owlmeans/server-auth`) — the bearer guard.
|
|
187
198
|
- `makeAuthServiceEntrypoints(serviceAlias, prefix = 'oidc-api')` (`@owlmeans/server-oidc-rp`) — returns `external-auth:provider:list` and `external-auth:auth:update` declarations, both behind `GUARD_ED25519`; bind them in the serving app.
|
|
188
199
|
- `makeOidcWrappingService`, `makeOidcGate`, `makeOidcClientService`, `appendOidcGuard`, `oidcEntrypoints` — wire OIDC services and server-local bindings into a server context (`@owlmeans/server-oidc-rp`). Decorate the app protocol tree with `withOidcGuard` from `@owlmeans/oidc` before binding it.
|
|
200
|
+
- `appendIam(context)` (`@owlmeans/server-iam`) — the same four registrations with the IAM gate in place of `makeOidcGate()`, for an application signing in against an IAM provider.
|
|
189
201
|
|
|
190
202
|
Client-side:
|
|
191
203
|
- `appendAuthService(ctx, alias?)` (`@owlmeans/client-auth`) — the client auth service with persistent storage.
|
|
192
204
|
- `setupExternalAuthentication(service)` (`@owlmeans/client-auth`) — point `CAUTHEN_FLOW_ENTER` at the service an external provider redirects into.
|
|
193
205
|
- `appendLogin(ctx)` (`@owlmeans/client-auth/login`) — the login-plugin host; `@owlmeans/web-client`'s `makeContext` already calls it.
|
|
194
206
|
- `appendOidcGuard()`, `oidcEntrypoints()` — `@owlmeans/web-oidc-rp` for browser-side bindings; `withOidcGuard` decorates the shared protocol tree.
|
|
207
|
+
- `appendIam(context, opts?)`, `withIamGuard`, `iamEntrypoints()` (`@owlmeans/client-iam`) — the same in one import, plus the consent-before-sign-in precondition and the organization switch.
|
|
195
208
|
|
|
196
209
|
Local identity and the organization entity:
|
|
197
|
-
- `appendAuthIdentityResources(context)` (`@owlmeans/server-auth-identity`) — registers the org-entity registry, the account/profile/credentials resources, the linking service
|
|
198
|
-
- `AUTH_IDENTITY_LINKING` — the service that maps provider profile details onto an `AuthPayload
|
|
199
|
-
- `AUTH_IDENTITY_PROFILE` — the
|
|
210
|
+
- `appendAuthIdentityResources(context, dbAlias?, { service? })` (`@owlmeans/server-auth-identity`) — registers the org-entity registry, the account/profile/credentials resources, the linking service for the deployment's own app key `service`, the entity resolver and the identity-events seam.
|
|
211
|
+
- `AUTH_IDENTITY_LINKING` — the service that maps provider profile details onto an `AuthPayload` of the deployment's own app.
|
|
212
|
+
- `AUTH_IDENTITY_PROFILE` — the profile rows: one per (account, app, organization), the record authorization reads (`role`, `scopes`, `permissions`, `groups`, optional expiry).
|
|
200
213
|
- `ENTITY_RESOLVER` — turns the token's `entitySlug` (current, retired, or the frozen `iamKey`) into a stable `OrgEntityRef`. Registering it is what tells the boundary this deployment has organizations.
|
|
201
214
|
|
|
202
215
|
Read identity records with `load()` or `list()`. Never use `take()` in an authorization lookup — it is delete-and-return, so it consumes the record it answers with.
|
|
@@ -217,6 +230,10 @@ resolved id and fall back to the slug where no resolver is registered. A boundar
|
|
|
217
230
|
leaves `request.entity` empty and its handlers silently compare a slug against stored ids — which
|
|
218
231
|
surfaces as "this record does not exist", not as a missing resolution.
|
|
219
232
|
|
|
233
|
+
A relying party of a tenanted client has no registry to resolve from: there the OIDC guard attaches
|
|
234
|
+
the session's acting organization itself, and `attachEntity` keeps it only while its slug is exactly
|
|
235
|
+
the token's (`auth-common` → "The organization entity").
|
|
236
|
+
|
|
220
237
|
## Mocking points (for category-B tests)
|
|
221
238
|
|
|
222
239
|
The protocol exposes three natural mocking boundaries. The only allowed implementation lives in `@owlmeans/test-auth`:
|
package/build/errors.d.ts
CHANGED
|
@@ -3,8 +3,16 @@ export declare class AuthError extends ResilientError {
|
|
|
3
3
|
static typeName: string;
|
|
4
4
|
constructor(message?: string);
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* The request names an authentication method, provider or identity this server does not know — an
|
|
8
|
+
* unregistered plugin type, a sign-in method a gate refuses, a request carrying no organization.
|
|
9
|
+
* That is the caller's request, not a crashed server, so it answers 400 (`httpStatus`, read by
|
|
10
|
+
* `@owlmeans/server-api`). It is outside the authorization family on purpose: a failed credential
|
|
11
|
+
* stays 401 (`AuthorizationError`) and a refused permission 403 (`AuthForbidden`).
|
|
12
|
+
*/
|
|
6
13
|
export declare class AuthUnknown extends AuthError {
|
|
7
14
|
static typeName: string;
|
|
15
|
+
static httpStatus: number;
|
|
8
16
|
constructor(message?: string);
|
|
9
17
|
}
|
|
10
18
|
export declare class AuthManagerError extends AuthError {
|
package/build/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MA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,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,OAAuB,QAAQ,EAAE,MAAM,CAAoC;IAE3E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,OAAuB,QAAQ,EAAE,MAAM,CAAuC;IAE9E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,kBAAmB,SAAQ,eAAe;IACrD,OAAuB,QAAQ,EAAE,MAAM,CAA6C;IAEpF,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,OAAuB,QAAQ,EAAE,MAAM,CAAuB;IAE9D,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,aAAc,SAAQ,kBAAkB;IACnD,OAAuB,QAAQ,EAAE,MAAM,CAA4C;IAEnF,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,YAAa,SAAQ,SAAS;IACzC,OAAuB,QAAQ,EAAE,MAAM,CAAiB;IAExD,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF;AAED,qBAAa,uBAAwB,SAAQ,YAAY;IACvD,OAAuB,QAAQ,EAAE,MAAM,CAAwC;IAE/E,YAAY,OAAO,GAAE,MAAgB,EAGpC;CACF"}
|
package/build/errors.js
CHANGED
|
@@ -5,8 +5,16 @@ export class AuthError extends ResilientError {
|
|
|
5
5
|
super(AuthError.typeName, `auth:${message}`);
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* The request names an authentication method, provider or identity this server does not know — an
|
|
10
|
+
* unregistered plugin type, a sign-in method a gate refuses, a request carrying no organization.
|
|
11
|
+
* That is the caller's request, not a crashed server, so it answers 400 (`httpStatus`, read by
|
|
12
|
+
* `@owlmeans/server-api`). It is outside the authorization family on purpose: a failed credential
|
|
13
|
+
* stays 401 (`AuthorizationError`) and a refused permission 403 (`AuthForbidden`).
|
|
14
|
+
*/
|
|
8
15
|
export class AuthUnknown extends AuthError {
|
|
9
16
|
static typeName = `${AuthError.typeName}Unknown`;
|
|
17
|
+
static httpStatus = 400;
|
|
10
18
|
constructor(message = 'error') {
|
|
11
19
|
super(`unknown:${message}`);
|
|
12
20
|
this.type = AuthUnknown.typeName;
|
package/build/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,OAAO,SAAU,SAAQ,cAAc;IACpC,MAAM,CAAU,QAAQ,GAAW,WAAW,CAAA;IAErD,YAAY,OAAO,GAAW,OAAO;QACnC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,OAAO,EAAE,CAAC,CAAA;IAC9C,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,SAAS;IACjC,MAAM,CAAU,QAAQ,GAAW,GAAG,SAAS,CAAC,QAAQ,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,OAAO,SAAU,SAAQ,cAAc;IACpC,MAAM,CAAU,QAAQ,GAAW,WAAW,CAAA;IAErD,YAAY,OAAO,GAAW,OAAO;QACnC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,OAAO,EAAE,CAAC,CAAA;IAC9C,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,WAAY,SAAQ,SAAS;IACjC,MAAM,CAAU,QAAQ,GAAW,GAAG,SAAS,CAAC,QAAQ,SAAS,CAAA;IACjE,MAAM,CAAC,UAAU,GAAG,GAAG,CAAA;IAE9B,YAAY,OAAO,GAAW,OAAO;QACnC,KAAK,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C,CAAA;AACrD,cAAc,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAA;AAClD,cAAc,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;AACrD,cAAc,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;AACrD,aAAa,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;AAC/C,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA;AAC/C,cAAc,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -9,9 +9,17 @@ export class AuthError extends ResilientError {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The request names an authentication method, provider or identity this server does not know — an
|
|
14
|
+
* unregistered plugin type, a sign-in method a gate refuses, a request carrying no organization.
|
|
15
|
+
* That is the caller's request, not a crashed server, so it answers 400 (`httpStatus`, read by
|
|
16
|
+
* `@owlmeans/server-api`). It is outside the authorization family on purpose: a failed credential
|
|
17
|
+
* stays 401 (`AuthorizationError`) and a refused permission 403 (`AuthForbidden`).
|
|
18
|
+
*/
|
|
12
19
|
export class AuthUnknown extends AuthError {
|
|
13
20
|
public static override typeName: string = `${AuthError.typeName}Unknown`
|
|
14
|
-
|
|
21
|
+
public static httpStatus = 400
|
|
22
|
+
|
|
15
23
|
constructor(message: string = 'error') {
|
|
16
24
|
super(`unknown:${message}`)
|
|
17
25
|
this.type = AuthUnknown.typeName
|
package/tests/errors.spec.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
AuthorizationError,
|
|
6
6
|
AuthenFailed,
|
|
7
7
|
AuthenPayloadError,
|
|
8
|
+
AuthUnknown,
|
|
8
9
|
} from '@owlmeans/auth'
|
|
9
10
|
|
|
10
11
|
describe('@owlmeans/auth — error inheritance chain', () => {
|
|
@@ -49,3 +50,21 @@ describe('@owlmeans/auth — error inheritance chain', () => {
|
|
|
49
50
|
expect(thrown).toHaveLength(3)
|
|
50
51
|
})
|
|
51
52
|
})
|
|
53
|
+
|
|
54
|
+
describe('@owlmeans/auth — declared HTTP statuses', () => {
|
|
55
|
+
// An unknown method, provider or identity is the caller's request — never a crashed server (500).
|
|
56
|
+
test('AuthUnknown declares 400 and stays outside the authorization family', () => {
|
|
57
|
+
const err = new AuthUnknown('email-otp')
|
|
58
|
+
expect(AuthUnknown.httpStatus).toBe(400)
|
|
59
|
+
expect((err.constructor as { httpStatus?: unknown }).httpStatus).toBe(400)
|
|
60
|
+
expect(err).toBeInstanceOf(AuthError)
|
|
61
|
+
expect(err).not.toBeInstanceOf(AuthorizationError)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Their 401/403 comes from the family mapping in `@owlmeans/server-api`, never from a declaration.
|
|
65
|
+
test('the authorization family declares no status of its own', () => {
|
|
66
|
+
for (const refusal of [AuthorizationError, AuthForbidden]) {
|
|
67
|
+
expect([refusal.typeName, (refusal as { httpStatus?: unknown }).httpStatus]).toEqual([refusal.typeName, undefined])
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
})
|