@owlmeans/auth 0.1.6 → 0.1.8
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 +17 -0
- package/agent-meta/instructions/auth-protocol.instructions.md +31 -0
- package/agent-meta/instructions/auth.instructions.md +59 -0
- package/agent-meta/manifest.json +37 -0
- package/agent-meta/skills/auth/SKILL.md +65 -0
- package/agent-meta/skills/auth-protocol/SKILL.md +184 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -79,3 +79,20 @@ enum AuthenticationStage { /* connection auth lifecycle */ }
|
|
|
79
79
|
- [`@owlmeans/auth-common`](../auth-common) — auth modules, guards, and middleware
|
|
80
80
|
- [`@owlmeans/server-auth`](../server-auth) — server-side auth service implementation
|
|
81
81
|
- [`@owlmeans/client-auth`](../client-auth) — client-side auth service
|
|
82
|
+
|
|
83
|
+
<!-- owlmeans:agent-guidance:start -->
|
|
84
|
+
## Agent guidance
|
|
85
|
+
|
|
86
|
+
This package ships embedded Claude Code skills and GitHub Copilot instructions under
|
|
87
|
+
`agent-meta/`. After installing your `@owlmeans/*` packages, run the OwlMeans
|
|
88
|
+
agent-skills installer to place them into your project's native locations
|
|
89
|
+
(`.claude/skills/` and `.github/instructions/`):
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
npx @owlmeans/agent-skills
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The embedded files are version-matched to this package release. Do not edit them
|
|
96
|
+
directly — they are regenerated on each publish. To contribute guidance edits,
|
|
97
|
+
open a PR against the source monorepo.
|
|
98
|
+
<!-- owlmeans:agent-guidance:end -->
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "OwlMeans auth protocol rules for Ed25519, OIDC, provider-backed local identity, guards, gates, errors, trust records, and auth test mocking. Use for auth*, *oidc*, server-auth-identity, did, wled, and client-payment package work."
|
|
3
|
+
applyTo: "**/*.ts, **/*.tsx"
|
|
4
|
+
---
|
|
5
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
|
+
|
|
7
|
+
# OwlMeans Auth Protocol — Code Rules
|
|
8
|
+
|
|
9
|
+
Two paths share the same `Auth`, `Authorization`, envelope shape and aliases:
|
|
10
|
+
|
|
11
|
+
- **Ed25519** (self-signed): allowance → credential → token-exchange → bearer `ED25519-BASIC-TOKEN <encoded>` → server-side `makeBasicEd25519Guard` verifies via `trust()` against the `TRUSTED` resource.
|
|
12
|
+
- **OIDC** (delegated): `makeOidcGuard` exchanges OAuth2 code, wraps the result in an `oidc-wrapped-token` envelope.
|
|
13
|
+
- **Provider-backed local identity** (used by product-viable): browser Google/OIDC plugin → server provider exchange → `@owlmeans/server-auth-identity` account/profile/credentials link → normal bearer token → product `GateService` authorizes against local profile scopes.
|
|
14
|
+
|
|
15
|
+
Aliases: `DEFAULT_GUARD = 'auth'`, `GUARD_ED25519 = 'guard:ed25519-basic-signature'`, `OIDC_GATE = 'oidc-gate'`, `AUTH_HEADER = 'authorization'`, `TOKEN_UPDATE = 'auth-token-refresh'`.
|
|
16
|
+
|
|
17
|
+
`AuthRole` is a **string** enum (`User`, `Guest`, `Service`, `System`, `Admin`, `Superuser`, `Blocked`). Never use numeric literals like `role: 0` — always use `AuthRole.User` etc.
|
|
18
|
+
|
|
19
|
+
Guard interface lives in `@owlmeans/entrypoint` (`GuardService` extends `InitializedService`, has `match`, `handle`, `authenticated`). Auth service extends it with `authenticate`, `update`, `user`, `store` (`@owlmeans/auth-common/types.ts`).
|
|
20
|
+
|
|
21
|
+
Envelope shape `{t, msg, sig?, dt, ttl}` from `@owlmeans/basic-envelope`. KeyPairModel `sign/verify/export/exportPublic` from `@owlmeans/basic-keys`.
|
|
22
|
+
|
|
23
|
+
When refactoring:
|
|
24
|
+
|
|
25
|
+
- Don't break the `match`/`handle`/`authenticated`/`unpack` contract — multiple guards rely on it.
|
|
26
|
+
- Trust-record lookups go through `trust(context, resource, userName, field?)`. Don't hard-code resource lookups.
|
|
27
|
+
- Errors must derive from the `@owlmeans/auth/errors` hierarchy (`AuthError`, `AuthenFailed`, `AuthenPayloadError`, `AuthorizationError`, `AuthForbidden`, …) so i18n + normalisation work.
|
|
28
|
+
- Local identity reads must be non-destructive. `Resource.pick()` deletes records; use `load()` or `list()` when checking `AUTH_IDENTITY_PROFILE` in authorization gates.
|
|
29
|
+
- New auth-related test mocks belong in `@owlmeans/test-auth` — not in a per-package `tests/` directory.
|
|
30
|
+
|
|
31
|
+
For the full protocol reference see `.claude/skills/auth-protocol/SKILL.md`.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "How to use @owlmeans/auth — core authentication types, errors (AuthUnknown, AuthError), permissions, allowance, rely, and entity primitives. Use when working with request authentication in handlers."
|
|
3
|
+
applyTo: "**/*.ts, **/*.tsx"
|
|
4
|
+
---
|
|
5
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
|
+
|
|
7
|
+
# @owlmeans/auth
|
|
8
|
+
|
|
9
|
+
**Layer:** Core
|
|
10
|
+
**Install:** `"@owlmeans/auth": "^0.1.8"` in `dependencies`
|
|
11
|
+
|
|
12
|
+
## Key Exports
|
|
13
|
+
|
|
14
|
+
| Export | Description |
|
|
15
|
+
|--------|-------------|
|
|
16
|
+
| `AuthUnknown` | Error thrown when expected entity/auth is missing on a request |
|
|
17
|
+
| `AuthError` and subclasses | Typed auth errors mapping to HTTP 401/403 |
|
|
18
|
+
| `Auth` types | Request auth payload shape (entityId, scopes, profile) |
|
|
19
|
+
| `Permission` helpers | Check scopes/permissions on a request |
|
|
20
|
+
| `Allowance` helpers | Inspect/grant allowances |
|
|
21
|
+
| `Entity`, `Rely` types | Shared entity-relationship primitives |
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { AuthUnknown } from '@owlmeans/auth'
|
|
27
|
+
import { handleRequest } from '@owlmeans/server-app'
|
|
28
|
+
|
|
29
|
+
export const list = handleRequest(async (req, context) => {
|
|
30
|
+
if (req.auth?.entityId == null) throw new AuthUnknown('entity')
|
|
31
|
+
return await (context as Context).project().list({ entityId: req.auth.entityId })
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Product-Viable Usage Notes
|
|
36
|
+
|
|
37
|
+
- `product-viable` handlers use `AuthUnknown('entity')` when a request should be authenticated but lacks `req.auth.entityId`.
|
|
38
|
+
- WebSocket helpers use `Auth`, `AuthToken`, and `AuthenticationStage` to move token-bearing connections into authenticated state.
|
|
39
|
+
- Google/OIDC login ultimately produces a normal `AuthPayload` with `userId`, `profileId`, `entityId`, and `scopes`; `@owlmeans/server-auth-identity` stores that local identity and returns the payload.
|
|
40
|
+
- Authorization failures in gates should use `AuthForbidden`, while missing handler auth/entity state usually uses `AuthUnknown`.
|
|
41
|
+
- Do not put product ownership rules in `@owlmeans/auth`; downstream apps compose `@owlmeans/entrypoint` gates or handler-level entity checks around these core types.
|
|
42
|
+
|
|
43
|
+
## AuthRole enum
|
|
44
|
+
|
|
45
|
+
`AuthRole` is a **string** enum (not numeric). Always use enum members — never assign a number literal to `role`:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { AuthRole } from '@owlmeans/auth'
|
|
49
|
+
|
|
50
|
+
const creds: AuthCredentials = { role: AuthRole.User, ... }
|
|
51
|
+
// WRONG: role: 0
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Members: `User`, `Guest`, `Service`, `System`, `Admin`, `Superuser`, `Blocked`.
|
|
55
|
+
|
|
56
|
+
## Depends On
|
|
57
|
+
|
|
58
|
+
- `@owlmeans/error` — base error class
|
|
59
|
+
- `@owlmeans/i18n` — translatable error messages
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"package": "@owlmeans/auth",
|
|
4
|
+
"version": "0.1.8",
|
|
5
|
+
"generatedAt": "2026-06-11T16:30:27.161Z",
|
|
6
|
+
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
|
+
"entries": [
|
|
8
|
+
{
|
|
9
|
+
"kind": "skill",
|
|
10
|
+
"name": "auth",
|
|
11
|
+
"category": "package-specific",
|
|
12
|
+
"file": "skills/auth/SKILL.md",
|
|
13
|
+
"canonicalPath": ".claude/skills/auth/SKILL.md"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"kind": "skill",
|
|
17
|
+
"name": "auth-protocol",
|
|
18
|
+
"category": "multi-package",
|
|
19
|
+
"file": "skills/auth-protocol/SKILL.md",
|
|
20
|
+
"canonicalPath": ".claude/skills/auth-protocol/SKILL.md"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"kind": "instruction",
|
|
24
|
+
"name": "auth-protocol",
|
|
25
|
+
"category": "multi-package",
|
|
26
|
+
"file": "instructions/auth-protocol.instructions.md",
|
|
27
|
+
"canonicalPath": ".github/instructions/auth-protocol.instructions.md"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"kind": "instruction",
|
|
31
|
+
"name": "auth",
|
|
32
|
+
"category": "package-specific",
|
|
33
|
+
"file": "instructions/auth.instructions.md",
|
|
34
|
+
"canonicalPath": ".github/instructions/auth.instructions.md"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: auth
|
|
3
|
+
description: How to use @owlmeans/auth — core authentication types, errors (AuthUnknown, AuthError), permissions, allowance, rely, and entity primitives shared across server and client. Auto-invoked when importing auth types/errors or working with request authentication.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
|
+
|
|
8
|
+
# @owlmeans/auth
|
|
9
|
+
|
|
10
|
+
**Layer:** Core
|
|
11
|
+
**Install:** `"@owlmeans/auth": "^0.1.8"` in `dependencies`
|
|
12
|
+
|
|
13
|
+
## Key Exports
|
|
14
|
+
|
|
15
|
+
| Export | Description |
|
|
16
|
+
|--------|-------------|
|
|
17
|
+
| `AuthUnknown` | Error thrown when expected entity/auth is missing on a request |
|
|
18
|
+
| `AuthError` and subclasses | Typed auth errors mapping to HTTP 401/403 |
|
|
19
|
+
| `Auth` types | Request auth payload shape (entityId, scopes, profile) |
|
|
20
|
+
| `Permission` helpers | Check scopes/permissions on a request |
|
|
21
|
+
| `Allowance` helpers | Inspect/grant allowances |
|
|
22
|
+
| `Entity`, `Rely` types | Shared entity-relationship primitives |
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Throw `AuthUnknown` from a handler when the auth context is missing the entity:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { AuthUnknown } from '@owlmeans/auth'
|
|
30
|
+
import { handleRequest } from '@owlmeans/server-app'
|
|
31
|
+
|
|
32
|
+
export const list = handleRequest(async (req, context) => {
|
|
33
|
+
if (req.auth?.entityId == null) throw new AuthUnknown('entity')
|
|
34
|
+
return await (context as Context).project().list({ entityId: req.auth.entityId })
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Product-Viable Usage Notes
|
|
39
|
+
|
|
40
|
+
- `product-viable` handlers use `AuthUnknown('entity')` when a request should be authenticated but lacks `req.auth.entityId`.
|
|
41
|
+
- WebSocket helpers use `Auth`, `AuthToken`, and `AuthenticationStage` to move token-bearing connections into authenticated state.
|
|
42
|
+
- Google/OIDC login ultimately produces a normal `AuthPayload` with `userId`, `profileId`, `entityId`, and `scopes`; `@owlmeans/server-auth-identity` stores that local identity and returns the payload.
|
|
43
|
+
- Authorization failures in gates should use `AuthForbidden`, while missing handler auth/entity state usually uses `AuthUnknown`.
|
|
44
|
+
- Keep product ownership rules outside `@owlmeans/auth`; downstream apps compose `@owlmeans/entrypoint` gates or handler-level entity checks around these core types.
|
|
45
|
+
|
|
46
|
+
## AuthRole enum
|
|
47
|
+
|
|
48
|
+
`AuthRole` is a **string** enum (not numeric). Always use the enum members — never assign a number literal to `role`:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { AuthRole } from '@owlmeans/auth'
|
|
52
|
+
|
|
53
|
+
// Correct
|
|
54
|
+
const creds: AuthCredentials = { role: AuthRole.User, ... }
|
|
55
|
+
|
|
56
|
+
// WRONG — will not compile
|
|
57
|
+
const creds: AuthCredentials = { role: 0, ... }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Members: `User`, `Guest`, `Service`, `System`, `Admin`, `Superuser`, `Blocked`.
|
|
61
|
+
|
|
62
|
+
## Depends On
|
|
63
|
+
|
|
64
|
+
- `@owlmeans/error` — `AuthUnknown` and friends extend `ResilientError`
|
|
65
|
+
- `@owlmeans/i18n` — for translatable error messages
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: auth-protocol
|
|
3
|
+
description: Comprehensive reference for the OwlMeans authentication and authorization protocol — Ed25519 path, OIDC path, provider-backed local identity, core types, errors, guards, gates, trust resource, envelope shape, refresh flow, and mocking points. Auto-invoked when files under auth*, *oidc*, server-auth-identity, did*, wled, client-payment are touched.
|
|
4
|
+
---
|
|
5
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
|
+
|
|
7
|
+
# OwlMeans Auth Protocol
|
|
8
|
+
|
|
9
|
+
This skill is the canonical reference for how authentication and authorization work across the monorepo. Read it before refactoring auth code, adding a new guard, or extending the auth-related packages.
|
|
10
|
+
|
|
11
|
+
## Protocol paths
|
|
12
|
+
|
|
13
|
+
The system supports multiple authentication paths that share the same `Auth` and `Authorization` types and the same envelope shape but diverge in the first half of the flow.
|
|
14
|
+
|
|
15
|
+
### Ed25519 (self-signed)
|
|
16
|
+
|
|
17
|
+
Use case: service-to-service, wallet provider, backend clients, high-security browser-issued tokens.
|
|
18
|
+
|
|
19
|
+
1. **Allowance**: client posts `AllowanceRequest` (a partial `AuthPayload`) to `/authentication/init`. Server returns `AllowanceResponse { challenge }`.
|
|
20
|
+
2. **Credential generation**: client builds `AuthCredentials` (challenge + ephemeral payload), signs the canonicalized payload with its Ed25519 keypair via `packAuthCredentials()` (`@owlmeans/basic-keys`), posts to `/authentication/authenticate`.
|
|
21
|
+
3. **Token exchange**: server resolves the signer from the `TRUSTED` config resource via `trust()` (`@owlmeans/auth-common`), verifies the signature, builds an `Auth`, wraps it in an `EnvelopeModel` of type `ed25519-basic-token` signed with the service's own key, and returns the tokenized envelope.
|
|
22
|
+
4. **Bearer**: client sends `Authorization: ED25519-BASIC-TOKEN <encoded>`.
|
|
23
|
+
5. **Server verification**: incoming requests hit `makeBasicEd25519Guard` (`@owlmeans/auth-common`) which `match`-es the header, `unpack`-s the envelope, and `handle`-s by resolving an `Auth` into the response.
|
|
24
|
+
|
|
25
|
+
### OIDC (delegated)
|
|
26
|
+
|
|
27
|
+
Use case: browser clients, third-party IdP integration, multi-tenant SaaS.
|
|
28
|
+
|
|
29
|
+
1. Standard OAuth2 code flow via `makeOidcGuard` (`@owlmeans/oidc`).
|
|
30
|
+
2. Server validates the ID token, wraps the resulting `Auth` in an envelope of type `oidc-wrapped-token` signed with the service key.
|
|
31
|
+
3. Subsequent requests carry the wrapped token; the OIDC guard verifies the envelope signature and freshness.
|
|
32
|
+
4. Refresh: `wrapper().update()` (`@owlmeans/oidc`) exchanges a stale token transparently — alias `TOKEN_UPDATE` (`@owlmeans/auth-common`).
|
|
33
|
+
|
|
34
|
+
### Provider-Backed Local Identity
|
|
35
|
+
|
|
36
|
+
Use case: apps such as `product-viable` that use Google/OIDC as login bootstrap but authorize against local product identity.
|
|
37
|
+
|
|
38
|
+
1. Browser imports `@owlmeans/web-oidc-rp/auth/plugins`, which registers OIDC and Google plugins in `@owlmeans/client-auth`.
|
|
39
|
+
2. The plugin persists auth control state, redirects to the provider, restores state on return, and submits code/query params as `AuthCredentials`.
|
|
40
|
+
3. Server exchanges the provider code through `@owlmeans/server-oidc-rp` and maps `ProviderProfileDetails` through `@owlmeans/server-auth-identity`.
|
|
41
|
+
4. `AUTH_IDENTITY_ACCOUNT`, `AUTH_IDENTITY_PROFILE`, and `AUTH_IDENTITY_CREDENTIALS` store local account/profile/provider-link data.
|
|
42
|
+
5. Server returns a normal OwlMeans bearer token. Downstream product gates authorize against local profile scopes, not against `OIDC_GATE`.
|
|
43
|
+
|
|
44
|
+
## Core types
|
|
45
|
+
|
|
46
|
+
Exported from `@owlmeans/auth`:
|
|
47
|
+
|
|
48
|
+
- `Auth` (l. 110) — the full authenticated identity, includes `token`, `userId`, `role`, `scopes`, `permissions?`, `attributes?`, `entityId?`, `createdAt`, `isUser`.
|
|
49
|
+
- `AuthPayload` (l. 27) — minimal identity tuple; `Auth extends AuthPayload`.
|
|
50
|
+
- `AuthCredentials` (l. 3) — challenge/response pair signed during authentication.
|
|
51
|
+
- `Authorization` (l. 77) — RBAC primitive: `entityId?`, `scopes`, `permissions?`, `attributes?`, `permissioned?`, `denormalized?`.
|
|
52
|
+
- `AllowanceRequest` (l. 150) — partial `AuthPayload` triggering challenge generation.
|
|
53
|
+
- `AllowanceResponse` (l. 172) — `{ challenge }`.
|
|
54
|
+
- `AuthToken` (l. 176) — `{ token }`, used in module query auth.
|
|
55
|
+
- `PermissionSet` (l. 134) / `Capabilties` (l. 141) / `AttributeSet` (l. 145) — scope-bound capability shapes.
|
|
56
|
+
|
|
57
|
+
## Enums and constants
|
|
58
|
+
|
|
59
|
+
`@owlmeans/auth` constants:
|
|
60
|
+
|
|
61
|
+
- `AuthRole` — **string** enum: `User`, `Guest`, `Service`, `System`, `Admin`, `Superuser`, `Blocked`. Never use numeric literals for `role` fields — always use `AuthRole.User` etc.
|
|
62
|
+
- `AuthenticationType` — `BasicEd25519`, `OneTimeToken`, `ReCaptcha`, `WalletDid`, `RelyHandshake`, `WalletConsumer`, `WalletProvider`.
|
|
63
|
+
- `AuthroizationType` (sic) — `AuthToken`, `Ed25519BasicToken`, `Ed25519BasicSignature`.
|
|
64
|
+
- `AUTH_HEADER = 'authorization'`, `AUTH_QUERY = 'token'`, `ENTITY_QUERY = 'entity'`, `PROFILE_QUERY = 'profile'`.
|
|
65
|
+
|
|
66
|
+
`@owlmeans/auth-common` constants:
|
|
67
|
+
|
|
68
|
+
- `DEF_AUTH_SRV = 'auth'` and its alias `DEFAULT_GUARD = 'auth'`.
|
|
69
|
+
- `TOKEN_UPDATE = 'auth-token-refresh'`.
|
|
70
|
+
- `DISPATCHER_PATH = '/dispatcher'`.
|
|
71
|
+
|
|
72
|
+
`@owlmeans/oidc` constants:
|
|
73
|
+
|
|
74
|
+
- `OIDC_GATE = 'oidc-gate'` — the `gate(...)` value to attach OIDC enforcement to a module.
|
|
75
|
+
- `GOOGLE_CLIENT_AUTH = 'google-oauth'` — browser plugin type for Google OAuth.
|
|
76
|
+
- `GOOGLE_SERVICE = 'google'` — provider service key used by backend config and identity linking.
|
|
77
|
+
|
|
78
|
+
For apps that use OIDC/Google only as a login provider and then authorize against local identity resources, declare a product-specific gate alias instead of reusing `OIDC_GATE`.
|
|
79
|
+
|
|
80
|
+
## Errors
|
|
81
|
+
|
|
82
|
+
`@owlmeans/auth` exports: `AuthError`, `AuthManagerError`, `AuthenFailed`, `AuthenExists`, `AuthenPayloadError`, `AuthPluginError`, `TypeMissmatchError`, `AuthorizationError`, `AuthForbidden`, `ProfileError`, `ProfileConsistencyError`. Each is i18n-aware via `@owlmeans/error`.
|
|
83
|
+
|
|
84
|
+
## Guard interface
|
|
85
|
+
|
|
86
|
+
`GuardService` (`@owlmeans/entrypoint`):
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
export interface GuardService extends InitializedService {
|
|
90
|
+
token?: string // client-side
|
|
91
|
+
authenticated: (req?: Partial<AbstractRequest>) => Promise<string | null>
|
|
92
|
+
match: EntrypointMatch // server-side
|
|
93
|
+
handle: EntrypointHandler
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`AuthService extends GuardService` with `authenticate(token)`, `update(token)`, `user()`, `store<T>()` — see `@owlmeans/auth-common`.
|
|
98
|
+
|
|
99
|
+
Guards are services registered on the context under their alias (`DEFAULT_GUARD` = `'auth'` is the canonical alias). A request is matched and handled by the guard whose `match()` returns `true`; `handle()` resolves an `Auth` into the response via `res.resolve(auth)`.
|
|
100
|
+
|
|
101
|
+
## Trust resource
|
|
102
|
+
|
|
103
|
+
`trust()` (`@owlmeans/auth-common`):
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
export const trust = async (context, resource, userName, field = 'name') => {
|
|
107
|
+
const trustedUser = await context.resource<Resource<TrustedRecord>>(resource).load(userName, field)
|
|
108
|
+
/* …keyPair derived from trustedUser.secret or trustedUser.credential… */
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`TrustedRecord` (`@owlmeans/auth-common`) extends `Profile` minus `permissions` / `attributes`. The `TRUSTED` config resource is the system's source of truth for known signing identities — the auth service, peer services, wallet providers, etc.
|
|
113
|
+
|
|
114
|
+
## Envelope shape
|
|
115
|
+
|
|
116
|
+
`@owlmeans/basic-envelope` envelope type:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
{
|
|
120
|
+
t: string // type, e.g. "ed25519-basic-token", "oidc-wrapped-token"
|
|
121
|
+
msg: string // base64(JSON.stringify(payload)) or raw string
|
|
122
|
+
sig?: string // signature over {t, msg, dt, ttl}
|
|
123
|
+
dt: number // creation timestamp (ms)
|
|
124
|
+
ttl: number | null // time-to-live (ms); null = no expiry
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`makeEnvelopeModel(type, kind?)` (`@owlmeans/basic-envelope`) builds a model with `send(msg, ttl)`, `sign(key, kind?)`, `verify(key)`, `tokenize()`, `wrap()`. `EnvelopeKind.Token` produces a string for HTTP headers; `EnvelopeKind.Wrap` produces a transport-friendly object.
|
|
129
|
+
|
|
130
|
+
## Key model
|
|
131
|
+
|
|
132
|
+
`KeyPairModel` (`@owlmeans/basic-keys`):
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
export interface KeyPairModel {
|
|
136
|
+
sign: (data) => Promise<string>
|
|
137
|
+
verify: (data, signature) => Promise<boolean>
|
|
138
|
+
export: () => string // private, "ed25519:<base64>"
|
|
139
|
+
exportPublic: () => string // public, "ed25519:<base64>"
|
|
140
|
+
exportAddress: () => string
|
|
141
|
+
encrypt / decrypt / dcrpt
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`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.
|
|
146
|
+
|
|
147
|
+
## Setup wiring
|
|
148
|
+
|
|
149
|
+
Server-side:
|
|
150
|
+
- `setupAuthServiceModules(modules, serviceAlias, prefix?)` (`@owlmeans/server-oidc-rp`) — registers provider list and token-update routes.
|
|
151
|
+
- `makeAuthService(alias)` (`@owlmeans/server-auth`) — factory for the server `AuthService`.
|
|
152
|
+
- `makeOidcWrappingService`, `makeOidcGate` — wire OIDC into a server context (`@owlmeans/server-oidc-rp`).
|
|
153
|
+
|
|
154
|
+
Client-side:
|
|
155
|
+
- `setupExternalAuthentication(service)` (`@owlmeans/client-auth`) — wire OAuth/OIDC flows for a client context.
|
|
156
|
+
- `appendAuthService(ctx, alias?)` (`@owlmeans/client-auth`) — attach the client auth service with persistent storage.
|
|
157
|
+
- `appendOidcGuard()`, `setupOidcGuard()` — `@owlmeans/web-oidc-rp` for browser-side.
|
|
158
|
+
|
|
159
|
+
Local identity:
|
|
160
|
+
- `appendAuthIdentityResources(context)` — registers identity account/profile/credentials resources and the linking service.
|
|
161
|
+
- `AUTH_IDENTITY_LINKING` — service that maps provider profile details into an `AuthPayload`.
|
|
162
|
+
- `AUTH_IDENTITY_PROFILE` — durable authorization profile with `entityId`, `role`, `scopes`, and optional expiry.
|
|
163
|
+
|
|
164
|
+
Read identity records with `load()` or `list()`. Do not use `pick()` for authorization lookups because `pick()` deletes the matching record.
|
|
165
|
+
|
|
166
|
+
## Mocking points (for category-B tests)
|
|
167
|
+
|
|
168
|
+
The protocol exposes three natural mocking boundaries. The only allowed implementation lives in `@owlmeans/test-auth`:
|
|
169
|
+
|
|
170
|
+
1. **Guard substitution.** Replace the guard service in the context with `makeMockGuard({ auth })` so `match` always hits and `handle` resolves a chosen `Auth`. This bypasses signature verification entirely — useful when the spec is about behaviour downstream of authentication.
|
|
171
|
+
2. **TRUSTED resource substitution.** Register `makeMemoryTrustedResource([records])` so `trust()` finds whichever signers your spec needs without touching real config.
|
|
172
|
+
3. **Fixture keys + envelopes.** `makeFixtureKeyPair(seed)` returns a deterministic `KeyPairModel`. `signMockEnvelope(msg, type, kind?, kp?)` produces a properly-signed envelope using a fixture key. `makeBearer(auth, kp?)` returns a header value `ED25519-BASIC-TOKEN <encoded>`.
|
|
173
|
+
|
|
174
|
+
The protocol does **not** ship a fake JWKS server. For OIDC-end-to-end tests, exercise the real `makeOidcGuard` against an in-memory trusted resource and a fixture keypair. If a downstream test needs a hostable IdP fake, add it to `@owlmeans/test-auth` (don't roll one in a per-package `tests/`).
|
|
175
|
+
|
|
176
|
+
## OIDC dependency boundary and pinned versions
|
|
177
|
+
|
|
178
|
+
The OIDC packages wrap four upstream libraries. **No upstream type from those libraries is re-exported** through any `@owlmeans/*` package's public index. All public contracts use OwlMeans-owned types; the mapping layer is confined to each package's `src/service.ts`.
|
|
179
|
+
|
|
180
|
+
Current exact pins (see [[oidc-versions]] for full upgrade checklist):
|
|
181
|
+
- `oidc-provider@9.8.4` — in `@owlmeans/server-oidc-provider`
|
|
182
|
+
- `jose@6.2.3` — in `server-oidc-provider` and `server-oidc-rp`
|
|
183
|
+
- `openid-client@6.8.4` — in `@owlmeans/server-oidc-rp`
|
|
184
|
+
- `oidc-client-ts@3.5.0` — in `@owlmeans/web-oidc-rp` and `@owlmeans/mui-oidc-rp`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/error": "^0.1.
|
|
25
|
+
"@owlmeans/error": "^0.1.8",
|
|
26
26
|
"ajv-formats": "^3.0.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|