@owlmeans/auth-common 0.1.2 → 0.1.4
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 +39 -280
- package/build/consts.d.ts +20 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +20 -0
- package/build/consts.js.map +1 -1
- package/build/guards/basic-ed25519/types.d.ts +1 -1
- package/build/guards/basic-ed25519/types.d.ts.map +1 -1
- package/build/middleware.js +2 -2
- package/build/middleware.js.map +1 -1
- package/build/modules.d.ts +2 -1
- package/build/modules.d.ts.map +1 -1
- package/build/modules.js +20 -14
- package/build/modules.js.map +1 -1
- package/build/types.d.ts +7 -1
- package/build/types.d.ts.map +1 -1
- package/build/utils/header.d.ts +1 -1
- package/build/utils/header.d.ts.map +1 -1
- package/package.json +16 -12
- package/src/consts.ts +22 -0
- package/src/guards/basic-ed25519/service.ts +1 -1
- package/src/guards/basic-ed25519/types.ts +1 -1
- package/src/middleware.ts +5 -5
- package/src/modules.ts +27 -14
- package/src/types.ts +9 -1
- package/src/utils/header.ts +1 -1
- package/tests/context.ts +48 -0
- package/tests/dispatcher.spec.ts +38 -0
- package/tests/header.spec.ts +32 -0
- package/tests/trusted.spec.ts +40 -0
- package/tsconfig.json +5 -10
package/README.md
CHANGED
|
@@ -1,318 +1,77 @@
|
|
|
1
1
|
# @owlmeans/auth-common
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Predefined authentication modules, guards, and constants shared between server and client packages.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
- **Common Types**: Shared interfaces and types used across client and server authentication implementations
|
|
12
|
-
- **Middleware**: Authentication middleware for request processing and token validation
|
|
13
|
-
- **Utility Functions**: Helper functions for authentication workflows and token management
|
|
14
|
-
|
|
15
|
-
This package follows the OwlMeans "quadra" pattern, providing common functionality that can be used by both server and client implementations.
|
|
7
|
+
- Exports standard auth module definitions (login, init, rely, dispatcher) ready to register in any app
|
|
8
|
+
- Provides `DEFAULT_GUARD` and `GUARD_ED25519` constants for protecting routes
|
|
9
|
+
- Implements the Basic ED25519 signature guard service for cryptographic request authentication
|
|
10
|
+
- Headers: `BED255_NONCE_HEADER`, `BED255_TIME_HEADER` for auth challenge/response
|
|
16
11
|
|
|
17
12
|
## Installation
|
|
18
13
|
|
|
19
14
|
```bash
|
|
20
|
-
|
|
15
|
+
bun add @owlmeans/auth-common
|
|
21
16
|
```
|
|
22
17
|
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
### Authentication Modules
|
|
26
|
-
|
|
27
|
-
In the OwlMeans ecosystem, modules represent URL units that define authentication routes and their behavior. The auth-common package provides standardized authentication modules for:
|
|
28
|
-
|
|
29
|
-
- **Backend Authentication**: Server-side authentication endpoints
|
|
30
|
-
- **Frontend Authentication**: Client-side authentication routes
|
|
31
|
-
- **Socket Authentication**: WebSocket authentication channels
|
|
32
|
-
- **Dispatcher Routes**: Authentication flow management and redirection
|
|
33
|
-
|
|
34
|
-
### Guards and Services
|
|
18
|
+
## Usage
|
|
35
19
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- **AuthService**: Core authentication service with token validation and user management
|
|
39
|
-
- **AuthorizationService**: Permission-based authorization service
|
|
40
|
-
- **GuardService**: Route protection and access control
|
|
41
|
-
|
|
42
|
-
## API Reference
|
|
43
|
-
|
|
44
|
-
### Types
|
|
45
|
-
|
|
46
|
-
#### `AuthRequest`
|
|
47
|
-
Extended request interface with authentication token in query parameters.
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
interface AuthRequest extends AbstractRequest {
|
|
51
|
-
query: AuthToken
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### `AuthUIParams`
|
|
56
|
-
Parameters for authentication UI components.
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
interface AuthUIParams {
|
|
60
|
-
type?: string // Authentication type identifier
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
#### `AuthService`
|
|
65
|
-
Core authentication service interface extending GuardService.
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
interface AuthService extends GuardService {
|
|
69
|
-
auth?: Auth // Current authentication state
|
|
70
|
-
authenticate: (token: AuthToken) => Promise<void> // Authenticate with token (throws AuthenFailed)
|
|
71
|
-
update: (token: string | undefined) => Promise<void> // Update authentication token
|
|
72
|
-
user: () => Auth // Get current authenticated user
|
|
73
|
-
store: <T extends ResourceRecord = ResourceRecord>() => Resource<T> // Get authentication storage resource
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**Methods:**
|
|
78
|
-
- **`authenticate(token: AuthToken): Promise<void>`**: Validates and sets authentication token. Throws `AuthenFailed` on invalid token.
|
|
79
|
-
- **`update(token: string | undefined): Promise<void>`**: Updates the current authentication token, useful for token refresh.
|
|
80
|
-
- **`user(): Auth`**: Returns the current authenticated user object.
|
|
81
|
-
- **`store<T>(): Resource<T>`**: Provides access to the authentication storage resource for persistence.
|
|
82
|
-
|
|
83
|
-
#### `AuthorizationService`
|
|
84
|
-
Service interface for permission-based authorization.
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
interface AuthorizationService extends InitializedService {
|
|
88
|
-
isAllowed: (permissions: string | string[] | PermissionSet | PermissionSet[], token?: string | AuthToken | null, thr?: boolean) => Promise<boolean>
|
|
89
|
-
update: (token?: string | AuthToken, thr?: boolean) => Promise<AuthToken | null>
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
**Methods:**
|
|
94
|
-
- **`isAllowed(permissions, token?, thr?): Promise<boolean>`**: Checks if given permissions are allowed for the token. Can throw on error if `thr` is true.
|
|
95
|
-
- **`update(token?, thr?): Promise<AuthToken | null>`**: Updates authorization context with new token and returns validated token.
|
|
96
|
-
|
|
97
|
-
#### `TrustedRecord`
|
|
98
|
-
Configuration record for trusted authentication entities.
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
interface TrustedRecord extends ConfigRecord, Partial<Omit<Profile, "permissions" | "attributes">> {
|
|
102
|
-
id: string // Unique identifier for the trusted entity
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Modules
|
|
107
|
-
|
|
108
|
-
The package exports a standardized set of authentication modules through the `modules` array:
|
|
109
|
-
|
|
110
|
-
#### Backend Modules
|
|
111
|
-
- **`AUTHEN`**: Base authentication endpoint (`/authentication`)
|
|
112
|
-
- **`AUTHEN_INIT`**: Authentication initialization (`/init`) - POST with AllowanceRequestSchema
|
|
113
|
-
- **`AUTHEN_AUTHEN`**: Authentication execution (`/authenticate`) - POST with AuthCredentialsSchema
|
|
114
|
-
- **`AUTHEN_RELY`**: WebSocket authentication rely (`/rely`) - with OptionalAuthTokenSchema
|
|
115
|
-
|
|
116
|
-
#### Frontend Modules
|
|
117
|
-
- **`CAUTHEN`**: Base client authentication (`/authentication`)
|
|
118
|
-
- **`CAUTHEN_AUTHEN`**: Client login page (`/login`)
|
|
119
|
-
- **`CAUTHEN_AUTHEN_DEFAULT`**: Default client auth route (`/`)
|
|
120
|
-
- **`CAUTHEN_AUTHEN_TYPED`**: Typed authentication (`/:type`)
|
|
121
|
-
- **`CAUTHEN_FLOW_ENTER`**: Authentication flow entry point (`/`)
|
|
122
|
-
|
|
123
|
-
#### Dispatcher Modules
|
|
124
|
-
- **`DISPATCHER`**: Authentication dispatcher (`/dispatcher`) - sticky module with AuthTokenSchema
|
|
125
|
-
- **`DISPATCHER_AUTHEN`**: Dispatcher authentication endpoint (`/authenticate`) - POST with AuthTokenSchema
|
|
20
|
+
Register the built-in auth modules and protect a route:
|
|
126
21
|
|
|
127
22
|
```typescript
|
|
128
23
|
import { modules } from '@owlmeans/auth-common'
|
|
24
|
+
import { GUARD_ED25519, DEFAULT_GUARD } from '@owlmeans/auth-common'
|
|
129
25
|
|
|
130
|
-
//
|
|
131
|
-
|
|
26
|
+
// Add auth modules to your app (includes /authentication, /login, /dispatcher routes)
|
|
27
|
+
await main(context, [...modules, ...appModules])
|
|
132
28
|
```
|
|
133
29
|
|
|
134
|
-
|
|
30
|
+
Protect a route with the ED25519 signature guard (re-exported via `@owlmeans/server-app`):
|
|
135
31
|
|
|
136
|
-
#### Rely Constants
|
|
137
32
|
```typescript
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const RELY_CALL_TIMEOUT = 120 // Rely call timeout in seconds
|
|
141
|
-
const RELY_ACTION_TIMEOUT = 600 // Rely action timeout in seconds
|
|
142
|
-
```
|
|
33
|
+
import { GUARD_ED25519 } from '@owlmeans/auth-common'
|
|
34
|
+
import { module, guard } from '@owlmeans/server-app'
|
|
143
35
|
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
const DISPATCHER_PATH = '/dispatcher' // Default dispatcher route path
|
|
147
|
-
const DEF_AUTH_SRV = 'auth' // Default authentication service name
|
|
148
|
-
const DEFAULT_GUARD = DEF_AUTH_SRV // Default guard service name
|
|
149
|
-
const TOKEN_UPDATE = 'auth-token-refresh' // Token update event name
|
|
36
|
+
const adminModule = module(route('admin', '/api/admin'), guard(GUARD_ED25519))
|
|
150
37
|
```
|
|
151
38
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
The package provides authentication guard implementations in the `/guards` subpackage:
|
|
39
|
+
## API
|
|
155
40
|
|
|
156
|
-
|
|
157
|
-
Authentication guard implementation for Ed25519 signature-based authentication.
|
|
41
|
+
### `modules`
|
|
158
42
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
43
|
+
Array of pre-built `CommonModule` instances covering the standard auth flow:
|
|
44
|
+
- `AUTHEN` — backend `/authentication` base route
|
|
45
|
+
- `AUTHEN_INIT` — POST `/authentication/init` (allowance request)
|
|
46
|
+
- `AUTHEN_AUTHEN` — POST `/authentication/authenticate` (credential submission)
|
|
47
|
+
- `AUTHEN_RELY` — WebSocket `/authentication/rely`
|
|
48
|
+
- `CAUTHEN`, `CAUTHEN_AUTHEN` — frontend auth routes
|
|
49
|
+
- `DISPATCHER` — frontend dispatcher route (sticky, handles redirect auth tokens)
|
|
162
50
|
|
|
163
|
-
###
|
|
164
|
-
|
|
165
|
-
Authentication utility functions are available in the `/utils` subpackage:
|
|
166
|
-
|
|
167
|
-
#### Header Utilities
|
|
168
|
-
Functions for managing authentication headers in HTTP requests.
|
|
169
|
-
|
|
170
|
-
#### Trusted Entity Utilities
|
|
171
|
-
Functions for managing trusted authentication entities and their validation.
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
import { /* utility functions */ } from '@owlmeans/auth-common/utils'
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
## Usage Examples
|
|
178
|
-
|
|
179
|
-
### Using Authentication Modules
|
|
180
|
-
|
|
181
|
-
```typescript
|
|
182
|
-
import { modules } from '@owlmeans/auth-common'
|
|
183
|
-
import { makeBasicContext } from '@owlmeans/context'
|
|
184
|
-
|
|
185
|
-
const context = makeBasicContext(config)
|
|
186
|
-
|
|
187
|
-
// Register all authentication modules
|
|
188
|
-
modules.forEach(module => {
|
|
189
|
-
context.registerModule(module)
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
await context.configure().init()
|
|
193
|
-
|
|
194
|
-
// Access specific authentication modules
|
|
195
|
-
const loginModule = context.module('cauthen-authen')
|
|
196
|
-
const authModule = context.module('authen')
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Implementing AuthService
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
import type { AuthService } from '@owlmeans/auth-common'
|
|
203
|
-
import { createService } from '@owlmeans/context'
|
|
204
|
-
|
|
205
|
-
const authService = createService<AuthService>('auth', {
|
|
206
|
-
auth: undefined,
|
|
207
|
-
|
|
208
|
-
async authenticate(token) {
|
|
209
|
-
// Validate token and set auth
|
|
210
|
-
const validatedAuth = await validateToken(token)
|
|
211
|
-
this.auth = validatedAuth
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
async update(token) {
|
|
215
|
-
if (token) {
|
|
216
|
-
await this.authenticate({ token })
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
user() {
|
|
221
|
-
if (!this.auth) {
|
|
222
|
-
throw new Error('No authenticated user')
|
|
223
|
-
}
|
|
224
|
-
return this.auth
|
|
225
|
-
},
|
|
226
|
-
|
|
227
|
-
store() {
|
|
228
|
-
// Return authentication storage resource
|
|
229
|
-
return authStorageResource
|
|
230
|
-
}
|
|
231
|
-
})
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
### Permission Checking
|
|
51
|
+
### Guard Constants
|
|
235
52
|
|
|
236
53
|
```typescript
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const authzService: AuthorizationService = context.service('authorization')
|
|
240
|
-
|
|
241
|
-
// Check single permission
|
|
242
|
-
const canRead = await authzService.isAllowed('read', userToken)
|
|
243
|
-
|
|
244
|
-
// Check multiple permissions
|
|
245
|
-
const canReadWrite = await authzService.isAllowed(['read', 'write'], userToken)
|
|
246
|
-
|
|
247
|
-
// Check with permission sets
|
|
248
|
-
const canAccess = await authzService.isAllowed([{
|
|
249
|
-
scope: 'documents',
|
|
250
|
-
permissions: { read: true, write: true }
|
|
251
|
-
}], userToken)
|
|
54
|
+
DEFAULT_GUARD // alias for the default auth service ('auth')
|
|
55
|
+
GUARD_ED25519 // guard name for Basic ED25519 signature authentication
|
|
252
56
|
```
|
|
253
57
|
|
|
254
|
-
###
|
|
58
|
+
### Header Constants (for WebSocket/HTTP auth challenges)
|
|
255
59
|
|
|
256
60
|
```typescript
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
//
|
|
260
|
-
const authServiceName = DEF_AUTH_SRV
|
|
261
|
-
|
|
262
|
-
// Set up dispatcher route
|
|
263
|
-
const dispatcherRoute = DISPATCHER_PATH
|
|
264
|
-
|
|
265
|
-
// Configure rely timeout
|
|
266
|
-
const relyTimeout = RELY_CALL_TIMEOUT * 1000 // Convert to milliseconds
|
|
61
|
+
BED255_NONCE_HEADER // 'X-Auth-Nonce'
|
|
62
|
+
BED255_TIME_HEADER // 'X-Auth-Time'
|
|
63
|
+
BED255_CASHE_RESOURCE // resource alias for nonce cache
|
|
267
64
|
```
|
|
268
65
|
|
|
269
|
-
## Integration
|
|
270
|
-
|
|
271
|
-
The auth-common package integrates with other OwlMeans packages:
|
|
66
|
+
## Product-Viable Integration Notes
|
|
272
67
|
|
|
273
|
-
-
|
|
274
|
-
-
|
|
275
|
-
-
|
|
276
|
-
-
|
|
277
|
-
- **@owlmeans/resource**: Data persistence and resource management
|
|
278
|
-
- **@owlmeans/route**: URL and routing infrastructure
|
|
279
|
-
|
|
280
|
-
## Package Structure
|
|
281
|
-
|
|
282
|
-
The authentication common library follows the OwlMeans package structure:
|
|
283
|
-
|
|
284
|
-
- **types**: TypeScript interfaces and type definitions
|
|
285
|
-
- **modules**: Predefined authentication modules for common flows
|
|
286
|
-
- **consts**: Static values and configuration constants
|
|
287
|
-
- **guards/**: Authentication guard implementations
|
|
288
|
-
- **utils/**: Internal utility functions for authentication workflows
|
|
289
|
-
- **middleware**: Authentication middleware for request processing
|
|
68
|
+
- `DEFAULT_GUARD` protects manager routes after bearer authentication is installed by `@owlmeans/server-auth`.
|
|
69
|
+
- Product authorization composes a custom gate inside `guard(DEFAULT_GUARD, gate(VIABLE_AUTH_GATE, [...]))` rather than using `OIDC_GATE` for Google login flows.
|
|
70
|
+
- `GUARD_ED25519` remains the service-to-service guard for internal/publisher/payment/auth-service calls.
|
|
71
|
+
- The browser-side alias from `@owlmeans/client-auth` must match the default guard name so shared module declarations elevate consistently.
|
|
290
72
|
|
|
291
73
|
## Related Packages
|
|
292
74
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
-
|
|
296
|
-
- **@owlmeans/client-auth**: Client-side authentication implementation
|
|
297
|
-
- **@owlmeans/web-oidc-provider**: OpenID Connect provider implementation
|
|
298
|
-
- **@owlmeans/web-oidc-rp**: OpenID Connect relying party implementation
|
|
299
|
-
|
|
300
|
-
## Error Handling
|
|
301
|
-
|
|
302
|
-
The package leverages the error types from `@owlmeans/auth`:
|
|
303
|
-
|
|
304
|
-
- **AuthenFailed**: Thrown by `authenticate()` method on authentication failure
|
|
305
|
-
- **AuthForbidden**: Thrown by authorization services on access denial
|
|
306
|
-
- **AuthError**: Base authentication error for general failures
|
|
307
|
-
|
|
308
|
-
Always handle authentication errors appropriately in your application:
|
|
309
|
-
|
|
310
|
-
```typescript
|
|
311
|
-
try {
|
|
312
|
-
await authService.authenticate(token)
|
|
313
|
-
} catch (error) {
|
|
314
|
-
if (error instanceof AuthenFailed) {
|
|
315
|
-
// Handle authentication failure
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
```
|
|
75
|
+
- [`@owlmeans/auth`](../auth) — auth type definitions and schemas
|
|
76
|
+
- [`@owlmeans/server-auth`](../server-auth) — server guard implementation
|
|
77
|
+
- [`@owlmeans/client-auth`](../client-auth) — client auth service
|
package/build/consts.d.ts
CHANGED
|
@@ -6,4 +6,24 @@ export declare const DISPATCHER_PATH = "/dispatcher";
|
|
|
6
6
|
export declare const DEF_AUTH_SRV = "auth";
|
|
7
7
|
export declare const DEFAULT_GUARD = "auth";
|
|
8
8
|
export declare const TOKEN_UPDATE = "auth-token-refresh";
|
|
9
|
+
export declare const WEB_API = "web-auth-api";
|
|
10
|
+
export declare const authApi: {
|
|
11
|
+
profile: {
|
|
12
|
+
base: string;
|
|
13
|
+
toEntityId: string;
|
|
14
|
+
};
|
|
15
|
+
entity: {
|
|
16
|
+
base: string;
|
|
17
|
+
get: string;
|
|
18
|
+
profile: {
|
|
19
|
+
base: string;
|
|
20
|
+
list: string;
|
|
21
|
+
link: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
auth: {
|
|
25
|
+
base: string;
|
|
26
|
+
delegate: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
9
29
|
//# sourceMappingURL=consts.d.ts.map
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,cAAc,CAAA;AAE1C,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAE9C,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,eAAO,MAAM,eAAe,gBAAgB,CAAA;AAE5C,eAAO,MAAM,YAAY,SAAS,CAAA;AAElC,eAAO,MAAM,aAAa,SAAe,CAAA;AAEzC,eAAO,MAAM,YAAY,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,cAAc,CAAA;AAE1C,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAE9C,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,eAAO,MAAM,eAAe,gBAAgB,CAAA;AAE5C,eAAO,MAAM,YAAY,SAAS,CAAA;AAElC,eAAO,MAAM,aAAa,SAAe,CAAA;AAEzC,eAAO,MAAM,YAAY,uBAAuB,CAAA;AAEhD,eAAO,MAAM,OAAO,iBAAiB,CAAA;AAErC,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;CAkBnB,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -6,4 +6,24 @@ export const DISPATCHER_PATH = '/dispatcher';
|
|
|
6
6
|
export const DEF_AUTH_SRV = 'auth';
|
|
7
7
|
export const DEFAULT_GUARD = DEF_AUTH_SRV;
|
|
8
8
|
export const TOKEN_UPDATE = 'auth-token-refresh';
|
|
9
|
+
export const WEB_API = 'web-auth-api';
|
|
10
|
+
export const authApi = {
|
|
11
|
+
profile: {
|
|
12
|
+
base: 'api:profile',
|
|
13
|
+
toEntityId: 'api:profile:to-entity-id',
|
|
14
|
+
},
|
|
15
|
+
entity: {
|
|
16
|
+
base: 'api:entity',
|
|
17
|
+
get: 'api:entity:get',
|
|
18
|
+
profile: {
|
|
19
|
+
base: 'api:entity:profile',
|
|
20
|
+
list: 'api:entity:profile:list',
|
|
21
|
+
link: 'api:entity:profile:link',
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
auth: {
|
|
25
|
+
base: 'api:auth',
|
|
26
|
+
delegate: 'api:auth:delegate',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
9
29
|
//# sourceMappingURL=consts.js.map
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAA;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAA;AAE9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAEtC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAA;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAA;AAElC,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAA;AAEzC,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAA;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAA;AAE9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAEtC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAA;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAA;AAElC,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAA;AAEzC,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAEhD,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAA;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO,EAAE;QACP,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE,0BAA0B;KACvC;IACD,MAAM,EAAE;QACN,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,gBAAgB;QACrB,OAAO,EAAE;YACP,IAAI,EAAE,oBAAoB;YAC1B,IAAI,EAAE,yBAAyB;YAC/B,IAAI,EAAE,yBAAyB;SAChC;KACF;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,mBAAmB;KAC9B;CACF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,MAAM,WAAW,iBAAkB,SAAQ,YAAY;CACtD;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
package/build/middleware.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MiddlewareType, MiddlewareStage, AppType } from '@owlmeans/context';
|
|
2
|
-
import { provideRequest } from '@owlmeans/client-
|
|
2
|
+
import { provideRequest } from '@owlmeans/client-entrypoint';
|
|
3
3
|
import { AUTH_HEADER } from '@owlmeans/auth';
|
|
4
4
|
export const authMiddleware = {
|
|
5
5
|
type: MiddlewareType.Context,
|
|
6
6
|
stage: MiddlewareStage.Loading,
|
|
7
7
|
apply: async (context) => {
|
|
8
|
-
context.
|
|
8
|
+
context.entrypoints().forEach(module => {
|
|
9
9
|
if (module.route.route.type === AppType.Backend && module.call != null) {
|
|
10
10
|
const guards = module.getGuards();
|
|
11
11
|
if (guards.length > 0) {
|
package/build/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG5C,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,IAAI,EAAE,cAAc,CAAC,OAAO;IAC5B,KAAK,EAAE,eAAe,CAAC,OAAO;IAC9B,KAAK,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;QACrB,OAAO,CAAC,WAAW,EAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC7C,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;gBACvE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;gBACjC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtB,IAAI,MAAM,CAAC,+BAA+B,KAAK,IAAI,EAAE,CAAC;wBACpD,OAAM;oBACR,CAAC;oBACD,MAAM,CAAC,+BAA+B,GAAG,IAAI,CAAA;oBAC7C,sDAAsD;oBACtD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;oBACxB,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;wBAC/B,+EAA+E;wBAC/E,sCAAsC;wBACtC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAC3C,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAe,KAAK,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CACjE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAA;wBAC5C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;4BAClB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;4BACtB,MAAM,IAAI,GAA6B,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;4BACjG,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAuC,CAAA;4BAC1E,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC;gCACjC,OAAO,CAAC,WAAW,CAAC,GAAG,KAAK,CAAA;gCAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;gCACtB,GAAG,GAAG,IAAkB,CAAA;4BAC1B,CAAC;wBACH,CAAC;wBAED,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;oBACvB,CAAC,CAAA;gBAEH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
package/build/modules.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export declare const modules: import("@owlmeans/
|
|
1
|
+
export declare const modules: import("@owlmeans/entrypoint").CommonEntrypoint[];
|
|
2
|
+
export declare const managerModules: import("@owlmeans/entrypoint").CommonEntrypoint[];
|
|
2
3
|
//# sourceMappingURL=modules.d.ts.map
|
package/build/modules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO,mDAuBnB,CAAA;AAED,eAAO,MAAM,cAAc,mDAW1B,CAAA"}
|
package/build/modules.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import { AUTHEN, AUTHEN_AUTHEN, AUTHEN_INIT, AUTHEN_RELY, AllowanceRequestSchema, AuthCredentialsSchema, AuthTokenSchema, CAUTHEN, CAUTHEN_AUTHEN, CAUTHEN_AUTHEN_DEFAULT, CAUTHEN_AUTHEN_TYPED, DISPATCHER, DISPATCHER_AUTHEN, OptionalAuthTokenSchema, CAUTHEN_FLOW_ENTER } from '@owlmeans/auth';
|
|
2
2
|
// import { AppType } from '@owlmeans/context'
|
|
3
|
-
import { body, filter,
|
|
3
|
+
import { body, filter, entrypoint, query } from '@owlmeans/entrypoint';
|
|
4
4
|
import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route';
|
|
5
|
-
import { DISPATCHER_PATH } from './consts.js';
|
|
5
|
+
import { DISPATCHER_PATH, WEB_API, authApi } from './consts.js';
|
|
6
6
|
export const modules = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
entrypoint(route(AUTHEN, '/authentication', backend())),
|
|
8
|
+
entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
|
|
9
|
+
entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
|
|
10
|
+
entrypoint(route(AUTHEN_RELY, '/rely', socket(AUTHEN)), filter(query(OptionalAuthTokenSchema))),
|
|
11
|
+
entrypoint(route(CAUTHEN, '/authentication', frontend())),
|
|
12
|
+
entrypoint(route(CAUTHEN_AUTHEN, '/login', frontend(CAUTHEN))),
|
|
13
|
+
entrypoint(route(CAUTHEN_AUTHEN_DEFAULT, '/', frontend(CAUTHEN_AUTHEN, true))),
|
|
14
|
+
entrypoint(route(CAUTHEN_AUTHEN_TYPED, '/:type', frontend(CAUTHEN_AUTHEN))),
|
|
15
15
|
// This is a helper route that is used by service providers to redirect to an external authentication service.
|
|
16
|
-
|
|
16
|
+
entrypoint(route(CAUTHEN_FLOW_ENTER, '/', frontend())),
|
|
17
17
|
// This is a helper route that is useb by service providres to process authentication provisioning via redirect.
|
|
18
18
|
// Also it can be default starting point to be redirected to an external identity provider.
|
|
19
|
-
|
|
19
|
+
entrypoint(route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
|
|
20
20
|
// This module is sticky - it means it's always attach to client router.
|
|
21
21
|
// It's required here cause every web app needs dispatcher route to authorize
|
|
22
22
|
// rediected users.
|
|
23
23
|
filter(query(AuthTokenSchema), { sticky: true })),
|
|
24
|
-
// This is a helper route that representes a API endpoint of service provider that wants to authenticate
|
|
24
|
+
// This is a helper route that representes a API endpoint of service provider that wants to authenticate
|
|
25
25
|
// a user with OwlMeans server-auth library.
|
|
26
|
-
|
|
26
|
+
entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
|
|
27
|
+
];
|
|
28
|
+
export const managerModules = [
|
|
29
|
+
entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
|
|
30
|
+
entrypoint(route(authApi.profile.toEntityId, '/to-entity-id', backend(authApi.profile.base, RouteMethod.POST))),
|
|
31
|
+
entrypoint(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
|
|
32
|
+
entrypoint(route(authApi.auth.delegate, '/delegate', backend(authApi.auth.base, RouteMethod.POST))),
|
|
27
33
|
];
|
|
28
34
|
// const skipModules = [DISPATCHER]
|
|
29
35
|
// export const authBackendModules = modules.filter(
|
package/build/modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,qBAAqB,EAC9F,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,UAAU,EAClG,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAC/D,MAAM,gBAAgB,CAAA;AACvB,8CAA8C;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"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"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Auth, AuthToken, PermissionSet, Profile } from '@owlmeans/auth';
|
|
2
2
|
import type { ConfigRecord, InitializedService } from '@owlmeans/context';
|
|
3
|
-
import type { AbstractRequest, GuardService } from '@owlmeans/
|
|
3
|
+
import type { AbstractRequest, GuardService } from '@owlmeans/entrypoint';
|
|
4
4
|
import type { Resource, ResourceRecord } from '@owlmeans/resource';
|
|
5
5
|
export interface AuthRequest extends AbstractRequest {
|
|
6
6
|
query: AuthToken;
|
|
@@ -25,4 +25,10 @@ export interface AuthorizationService extends InitializedService {
|
|
|
25
25
|
export interface TrustedRecord extends ConfigRecord, Partial<Omit<Profile, "permissions" | "attributes">> {
|
|
26
26
|
id: string;
|
|
27
27
|
}
|
|
28
|
+
export interface ProfileToEntityIdRequest {
|
|
29
|
+
profileId: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ProfileToEntityIdResponse {
|
|
32
|
+
entityId: string;
|
|
33
|
+
}
|
|
28
34
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAElE,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,KAAK,EAAE,SAAS,CAAA;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,IAAI,CAAC,EAAE,IAAI,CAAA;IACX;;OAEG;IACH,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,IAAI,EAAE,MAAM,IAAI,CAAA;IAEhB,KAAK,EAAE,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAA;CACpE;AAED,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,SAAS,EAAE,CACT,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,GAAG,aAAa,EAAE,EAChE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACjC,GAAG,CAAC,EAAE,OAAO,KACV,OAAO,CAAC,OAAO,CAAC,CAAA;IAErB,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;CACjF;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAAC,CAAC;IACvG,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAA;CACjB"}
|
package/build/utils/header.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AbstractRequest } from '@owlmeans/
|
|
1
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint';
|
|
2
2
|
export declare const extractAuthToken: (req: Partial<AbstractRequest>, type?: string | null, onlyValue?: boolean) => string | null;
|
|
3
3
|
//# sourceMappingURL=header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../src/utils/header.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../src/utils/header.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,eAAO,MAAM,gBAAgB,GAC3B,KAAK,OAAO,CAAC,eAAe,CAAC,EAC7B,OAAM,MAAM,GAAG,IAA0C,EACzD,YAAW,OAAc,KACxB,MAAM,GAAG,IAgBX,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/auth-common",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc -b",
|
|
8
8
|
"dev": "sleep 30 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
|
|
9
|
-
"watch": "tsc -b -w --preserveWatchOutput --pretty"
|
|
9
|
+
"watch": "tsc -b -w --preserveWatchOutput --pretty",
|
|
10
|
+
"test": "bun test ./tests"
|
|
10
11
|
},
|
|
11
12
|
"main": "build/index.js",
|
|
12
13
|
"module": "build/index.js",
|
|
@@ -28,20 +29,23 @@
|
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@owlmeans/auth": "^0.1.
|
|
32
|
-
"@owlmeans/auth-common": "^0.1.
|
|
33
|
-
"@owlmeans/basic-ids": "^0.1.
|
|
34
|
-
"@owlmeans/basic-keys": "^0.1.
|
|
35
|
-
"@owlmeans/client-
|
|
36
|
-
"@owlmeans/context": "^0.1.
|
|
37
|
-
"@owlmeans/
|
|
38
|
-
"@owlmeans/resource": "^0.1.
|
|
39
|
-
"@owlmeans/route": "^0.1.
|
|
32
|
+
"@owlmeans/auth": "^0.1.4",
|
|
33
|
+
"@owlmeans/auth-common": "^0.1.4",
|
|
34
|
+
"@owlmeans/basic-ids": "^0.1.4",
|
|
35
|
+
"@owlmeans/basic-keys": "^0.1.4",
|
|
36
|
+
"@owlmeans/client-entrypoint": "^0.1.4",
|
|
37
|
+
"@owlmeans/context": "^0.1.4",
|
|
38
|
+
"@owlmeans/entrypoint": "^0.1.4",
|
|
39
|
+
"@owlmeans/resource": "^0.1.4",
|
|
40
|
+
"@owlmeans/route": "^0.1.4"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
43
|
+
"@owlmeans/dep-config": "workspace:*",
|
|
44
|
+
"@owlmeans/test-auth": "^0.1.4",
|
|
45
|
+
"@types/bun": "^1.3.0",
|
|
42
46
|
"nodemon": "^3.1.11",
|
|
43
47
|
"npm-check": "^6.0.1",
|
|
44
|
-
"typescript": "^
|
|
48
|
+
"typescript": "^6.0.2"
|
|
45
49
|
},
|
|
46
50
|
"publishConfig": {
|
|
47
51
|
"access": "public"
|
package/src/consts.ts
CHANGED
|
@@ -14,3 +14,25 @@ export const DEFAULT_GUARD = DEF_AUTH_SRV
|
|
|
14
14
|
|
|
15
15
|
export const TOKEN_UPDATE = 'auth-token-refresh'
|
|
16
16
|
|
|
17
|
+
export const WEB_API = 'web-auth-api'
|
|
18
|
+
|
|
19
|
+
export const authApi = {
|
|
20
|
+
profile: {
|
|
21
|
+
base: 'api:profile',
|
|
22
|
+
toEntityId: 'api:profile:to-entity-id',
|
|
23
|
+
},
|
|
24
|
+
entity: {
|
|
25
|
+
base: 'api:entity',
|
|
26
|
+
get: 'api:entity:get',
|
|
27
|
+
profile: {
|
|
28
|
+
base: 'api:entity:profile',
|
|
29
|
+
list: 'api:entity:profile:list',
|
|
30
|
+
link: 'api:entity:profile:link',
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
auth: {
|
|
34
|
+
base: 'api:auth',
|
|
35
|
+
delegate: 'api:auth:delegate',
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createService } from '@owlmeans/context'
|
|
2
|
-
import type { AbstractRequest, AbstractResponse } from '@owlmeans/
|
|
2
|
+
import type { AbstractRequest, AbstractResponse } from '@owlmeans/entrypoint'
|
|
3
3
|
import { assertContext } from '@owlmeans/context'
|
|
4
4
|
import {
|
|
5
5
|
BED255_NONCE_HEADER, BED255_TIME_HEADER, BED255_CASHE_RESOURCE, GUARD_ED25519,
|
package/src/middleware.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Middleware } from '@owlmeans/context'
|
|
2
2
|
import { MiddlewareType, MiddlewareStage, AppType } from '@owlmeans/context'
|
|
3
|
-
import { provideRequest } from '@owlmeans/client-
|
|
4
|
-
import type {
|
|
3
|
+
import { provideRequest } from '@owlmeans/client-entrypoint'
|
|
4
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
5
5
|
import { AUTH_HEADER } from '@owlmeans/auth'
|
|
6
|
-
import type { AbstractRequest, GuardService } from '@owlmeans/
|
|
6
|
+
import type { AbstractRequest, GuardService } from '@owlmeans/entrypoint'
|
|
7
7
|
|
|
8
8
|
export const authMiddleware: Middleware = {
|
|
9
9
|
type: MiddlewareType.Context,
|
|
10
10
|
stage: MiddlewareStage.Loading,
|
|
11
11
|
apply: async context => {
|
|
12
|
-
context.
|
|
12
|
+
context.entrypoints<Perked>().forEach(module => {
|
|
13
13
|
if (module.route.route.type === AppType.Backend && module.call != null) {
|
|
14
14
|
const guards = module.getGuards()
|
|
15
15
|
if (guards.length > 0) {
|
|
@@ -45,6 +45,6 @@ export const authMiddleware: Middleware = {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
interface Perked extends
|
|
48
|
+
interface Perked extends ClientEntrypoint<unknown> {
|
|
49
49
|
_auth_common_middleware_applied?: boolean
|
|
50
50
|
}
|
package/src/modules.ts
CHANGED
|
@@ -5,33 +5,46 @@ import {
|
|
|
5
5
|
DISPATCHER_AUTHEN, OptionalAuthTokenSchema, CAUTHEN_FLOW_ENTER
|
|
6
6
|
} from '@owlmeans/auth'
|
|
7
7
|
// import { AppType } from '@owlmeans/context'
|
|
8
|
-
import { body, filter,
|
|
8
|
+
import { body, filter, entrypoint, query } from '@owlmeans/entrypoint'
|
|
9
9
|
import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route'
|
|
10
|
-
import { DISPATCHER_PATH } from './consts.js'
|
|
10
|
+
import { DISPATCHER_PATH, WEB_API, authApi } from './consts.js'
|
|
11
11
|
|
|
12
12
|
export const modules = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
entrypoint(route(AUTHEN, '/authentication', backend())),
|
|
14
|
+
entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
|
|
15
|
+
entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
|
|
16
|
+
entrypoint(route(AUTHEN_RELY, '/rely', socket(AUTHEN)), filter(query(OptionalAuthTokenSchema))),
|
|
17
|
+
entrypoint(route(CAUTHEN, '/authentication', frontend())),
|
|
18
|
+
entrypoint(route(CAUTHEN_AUTHEN, '/login', frontend(CAUTHEN))),
|
|
19
|
+
entrypoint(route(CAUTHEN_AUTHEN_DEFAULT, '/', frontend(CAUTHEN_AUTHEN, true))),
|
|
20
|
+
entrypoint(route(CAUTHEN_AUTHEN_TYPED, '/:type', frontend(CAUTHEN_AUTHEN))),
|
|
21
21
|
// This is a helper route that is used by service providers to redirect to an external authentication service.
|
|
22
|
-
|
|
22
|
+
entrypoint(route(CAUTHEN_FLOW_ENTER, '/', frontend())),
|
|
23
23
|
// This is a helper route that is useb by service providres to process authentication provisioning via redirect.
|
|
24
24
|
// Also it can be default starting point to be redirected to an external identity provider.
|
|
25
|
-
|
|
25
|
+
entrypoint(
|
|
26
26
|
route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
|
|
27
27
|
// This module is sticky - it means it's always attach to client router.
|
|
28
28
|
// It's required here cause every web app needs dispatcher route to authorize
|
|
29
29
|
// rediected users.
|
|
30
30
|
filter(query(AuthTokenSchema), { sticky: true })
|
|
31
31
|
),
|
|
32
|
-
// This is a helper route that representes a API endpoint of service provider that wants to authenticate
|
|
32
|
+
// This is a helper route that representes a API endpoint of service provider that wants to authenticate
|
|
33
33
|
// a user with OwlMeans server-auth library.
|
|
34
|
-
|
|
34
|
+
entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
export const managerModules = [
|
|
38
|
+
entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
|
|
39
|
+
entrypoint(route(
|
|
40
|
+
authApi.profile.toEntityId, '/to-entity-id',
|
|
41
|
+
backend(authApi.profile.base, RouteMethod.POST)
|
|
42
|
+
)),
|
|
43
|
+
entrypoint(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
|
|
44
|
+
entrypoint(route(
|
|
45
|
+
authApi.auth.delegate, '/delegate',
|
|
46
|
+
backend(authApi.auth.base, RouteMethod.POST)
|
|
47
|
+
)),
|
|
35
48
|
]
|
|
36
49
|
|
|
37
50
|
// const skipModules = [DISPATCHER]
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Auth, AuthToken, PermissionSet, Profile } from '@owlmeans/auth'
|
|
2
2
|
import type { ConfigRecord, InitializedService } from '@owlmeans/context'
|
|
3
|
-
import type { AbstractRequest, GuardService } from '@owlmeans/
|
|
3
|
+
import type { AbstractRequest, GuardService } from '@owlmeans/entrypoint'
|
|
4
4
|
import type { Resource, ResourceRecord } from '@owlmeans/resource'
|
|
5
5
|
|
|
6
6
|
export interface AuthRequest extends AbstractRequest {
|
|
@@ -36,3 +36,11 @@ export interface AuthorizationService extends InitializedService {
|
|
|
36
36
|
export interface TrustedRecord extends ConfigRecord, Partial<Omit<Profile, "permissions" | "attributes">> {
|
|
37
37
|
id: string
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
export interface ProfileToEntityIdRequest {
|
|
41
|
+
profileId: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ProfileToEntityIdResponse {
|
|
45
|
+
entityId: string
|
|
46
|
+
}
|
package/src/utils/header.ts
CHANGED
package/tests/context.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
|
|
2
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context'
|
|
3
|
+
import { makeMemoryTrustedResource, makeFixtureKeyPair } from '@owlmeans/test-auth'
|
|
4
|
+
import type { TrustedRecord } from '@owlmeans/auth-common'
|
|
5
|
+
import type { KeyPairModel } from '@owlmeans/basic-keys'
|
|
6
|
+
|
|
7
|
+
export const TRUSTED_ALIAS = 'TRUSTED'
|
|
8
|
+
|
|
9
|
+
export interface TrustFixture {
|
|
10
|
+
ctx: BasicContext<BasicConfig>
|
|
11
|
+
authKey: KeyPairModel
|
|
12
|
+
authRecord: TrustedRecord
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Build a real `BasicContext` with an in-memory TRUSTED resource pre-populated
|
|
17
|
+
* with a single trusted user — mirroring the way viable apps populate
|
|
18
|
+
* `cfg.trusted` (see /home/igor/projects/owlmeans/viable/sources/backend/src/config.ts:62-109).
|
|
19
|
+
*
|
|
20
|
+
* Returns the context, the fixture keypair we used to build the record, and
|
|
21
|
+
* the record itself so specs can re-use them when asserting `trust()`'s return.
|
|
22
|
+
*/
|
|
23
|
+
export const makeTrustFixture = (
|
|
24
|
+
options: { withSecret?: boolean, name?: string, seed?: string } = {}
|
|
25
|
+
): TrustFixture => {
|
|
26
|
+
const seed = options.seed ?? 'auth-common-tests'
|
|
27
|
+
const name = options.name ?? 'auth-service'
|
|
28
|
+
const authKey = makeFixtureKeyPair(seed)
|
|
29
|
+
|
|
30
|
+
const authRecord: TrustedRecord = {
|
|
31
|
+
id: authKey.exportAddress(),
|
|
32
|
+
name,
|
|
33
|
+
credential: authKey.exportPublic(),
|
|
34
|
+
...(options.withSecret === true ? { secret: authKey.export() } : {}),
|
|
35
|
+
scopes: ['*'],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ctx = makeBasicContext<BasicConfig>({
|
|
39
|
+
ready: false,
|
|
40
|
+
service: 'auth-common-tests',
|
|
41
|
+
layer: Layer.Service,
|
|
42
|
+
type: AppType.Backend,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
ctx.registerResource(makeMemoryTrustedResource([authRecord], TRUSTED_ALIAS))
|
|
46
|
+
|
|
47
|
+
return { ctx, authKey, authRecord }
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { modules } from '@owlmeans/auth-common'
|
|
3
|
+
import { DISPATCHER, DISPATCHER_AUTHEN } from '@owlmeans/auth'
|
|
4
|
+
import { DISPATCHER_PATH } from '../src/consts.js'
|
|
5
|
+
|
|
6
|
+
// The DISPATCHER module intentionally declares service: DISPATCHER so that
|
|
7
|
+
// urlCall() produces an absolute URL (pointing to the auth service).
|
|
8
|
+
// The fix for the React Router 404 ("/https:/vib.owl.flat/dispatcher") lives
|
|
9
|
+
// in @owlmeans/client's navigator.navigate() — when the URL is absolute it
|
|
10
|
+
// does a browser redirect (globalThis.location.href) instead of React Router navigate().
|
|
11
|
+
|
|
12
|
+
describe('@owlmeans/auth-common — DISPATCHER module declaration', () => {
|
|
13
|
+
const dispatcher = modules.find(m => m.route.route.alias === DISPATCHER)
|
|
14
|
+
|
|
15
|
+
test('DISPATCHER module is present in the modules array', () => {
|
|
16
|
+
expect(dispatcher).toBeDefined()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('DISPATCHER route has an explicit service override (cross-service)', () => {
|
|
20
|
+
// service: DISPATCHER is intentional — the dispatcher belongs to the auth service.
|
|
21
|
+
// The navigator in @owlmeans/client handles the resulting absolute URL correctly.
|
|
22
|
+
expect(dispatcher?.route.route.service).toBe(DISPATCHER)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('DISPATCHER route path is DISPATCHER_PATH (/dispatcher)', () => {
|
|
26
|
+
expect(dispatcher?.route.route.path).toBe(DISPATCHER_PATH)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('DISPATCHER module is sticky (always registered in every app router)', () => {
|
|
30
|
+
expect(dispatcher?.sticky).toBe(true)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('DISPATCHER_AUTHEN backend module is distinct', () => {
|
|
34
|
+
const dispatcherAuthen = modules.find(m => m.route.route.alias === DISPATCHER_AUTHEN)
|
|
35
|
+
expect(dispatcherAuthen).toBeDefined()
|
|
36
|
+
expect(dispatcherAuthen?.sticky).toBeFalsy()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { extractAuthToken } from '@owlmeans/auth-common/utils'
|
|
3
|
+
import { AUTH_HEADER, AuthroizationType } from '@owlmeans/auth'
|
|
4
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
5
|
+
|
|
6
|
+
const reqWith = (header: string | undefined): Partial<AbstractRequest> => ({
|
|
7
|
+
headers: header == null ? {} : { [AUTH_HEADER]: header },
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
describe('@owlmeans/auth-common — extractAuthToken', () => {
|
|
11
|
+
// The basic-ed25519 guard at packages/auth-common/src/guards/basic-ed25519/service.ts:64
|
|
12
|
+
// calls extractAuthToken(req, AuthroizationType.Ed25519BasicSignature) inside `match`.
|
|
13
|
+
// viable/sources/publisher/src/helpers/ws-auth.ts also reads AUTH_HEADER directly.
|
|
14
|
+
test('returns the value when the header prefix matches the expected type', () => {
|
|
15
|
+
const req = reqWith(`${AuthroizationType.Ed25519BasicToken.toUpperCase()} abc.def`)
|
|
16
|
+
expect(extractAuthToken(req, AuthroizationType.Ed25519BasicToken)).toBe('abc.def')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('returns null when the header prefix does not match', () => {
|
|
20
|
+
const req = reqWith(`${AuthroizationType.Ed25519BasicSignature.toUpperCase()} abc.def`)
|
|
21
|
+
expect(extractAuthToken(req, AuthroizationType.Ed25519BasicToken)).toBeNull()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('returns null when the Authorization header is absent', () => {
|
|
25
|
+
expect(extractAuthToken(reqWith(undefined), AuthroizationType.Ed25519BasicToken)).toBeNull()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('with type=null returns the raw value irrespective of prefix', () => {
|
|
29
|
+
const req = reqWith('CUSTOM-PREFIX raw-value')
|
|
30
|
+
expect(extractAuthToken(req, null)).toBe('raw-value')
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { trust } from '@owlmeans/auth-common/utils'
|
|
3
|
+
import { TRUSTED_ALIAS, makeTrustFixture } from './context.js'
|
|
4
|
+
|
|
5
|
+
describe('@owlmeans/auth-common — trust() flow', () => {
|
|
6
|
+
// Mirrors viable/sources/backend/src/config.ts which pushes trusted records
|
|
7
|
+
// for master-key/auth-service/payment-service/agent — each with a `name`
|
|
8
|
+
// field that downstream `trust(context, resource, userName)` calls look up.
|
|
9
|
+
test('loads a record by name and returns a verifying key model', async () => {
|
|
10
|
+
const { ctx, authKey, authRecord } = makeTrustFixture()
|
|
11
|
+
|
|
12
|
+
const { user, key } = await trust(ctx, TRUSTED_ALIAS, authRecord.name as string)
|
|
13
|
+
|
|
14
|
+
expect(user.id).toBe(authRecord.id as string)
|
|
15
|
+
const sig = await authKey.sign({ a: 1 })
|
|
16
|
+
expect(await key.verify({ a: 1 }, sig)).toBe(true)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('returns a signing key model when the trusted record has a `secret`', async () => {
|
|
20
|
+
const { ctx, authRecord } = makeTrustFixture({ withSecret: true })
|
|
21
|
+
|
|
22
|
+
const { key } = await trust(ctx, TRUSTED_ALIAS, authRecord.name as string)
|
|
23
|
+
|
|
24
|
+
// With secret in the record the model can sign as well as verify —
|
|
25
|
+
// this is the path used by the auth service itself when issuing tokens.
|
|
26
|
+
const sig = await key.sign({ a: 1 })
|
|
27
|
+
expect(await key.verify({ a: 1 }, sig)).toBe(true)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('throws SyntaxError when the trusted user is missing', async () => {
|
|
31
|
+
const { ctx } = makeTrustFixture()
|
|
32
|
+
|
|
33
|
+
let caught: unknown = null
|
|
34
|
+
try {
|
|
35
|
+
await trust(ctx, TRUSTED_ALIAS, 'unknown-user')
|
|
36
|
+
} catch (e) { caught = e }
|
|
37
|
+
|
|
38
|
+
expect(caught).toBeInstanceOf(SyntaxError)
|
|
39
|
+
})
|
|
40
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": [
|
|
3
|
-
"
|
|
3
|
+
"@owlmeans/dep-config/tsconfig.base.json"
|
|
4
4
|
],
|
|
5
5
|
"compilerOptions": {
|
|
6
|
-
"rootDir": "./src/",
|
|
7
|
-
"outDir": "./build/"
|
|
8
|
-
"moduleResolution": "Bundler"
|
|
6
|
+
"rootDir": "./src/",
|
|
7
|
+
"outDir": "./build/"
|
|
9
8
|
},
|
|
10
|
-
"exclude": [
|
|
11
|
-
|
|
12
|
-
"./build/**/*",
|
|
13
|
-
"./*.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
9
|
+
"exclude": ["./dist/**/*", "./build/**/*", "./tests/**/*", "./*.ts"]
|
|
10
|
+
}
|