@owlmeans/client-auth 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 +32 -489
- package/build/components/dispatcher/component.js.map +1 -1
- package/build/components/dispatcher/types.d.ts +1 -1
- package/build/components/dispatcher/types.d.ts.map +1 -1
- package/build/helper.d.ts +3 -3
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +2 -2
- package/build/helper.js.map +1 -1
- package/build/manager/components/authentication/control.js +4 -4
- package/build/manager/components/authentication/control.js.map +1 -1
- package/build/manager/modules.d.ts +1 -1
- package/build/manager/modules.d.ts.map +1 -1
- package/build/manager/modules.js +1 -1
- package/build/manager/modules.js.map +1 -1
- package/build/modules.d.ts +2 -2
- package/build/modules.d.ts.map +1 -1
- package/build/modules.js +1 -1
- package/build/modules.js.map +1 -1
- package/build/service.js +1 -1
- package/build/service.js.map +1 -1
- package/package.json +25 -21
- package/src/components/dispatcher/component.tsx +3 -3
- package/src/components/dispatcher/types.ts +1 -1
- package/src/helper.ts +5 -5
- package/src/manager/components/authentication/control.ts +5 -5
- package/src/manager/modules.ts +1 -1
- package/src/modules.ts +3 -3
- package/src/service.ts +2 -2
- package/tests/context.ts +27 -0
- package/tests/service.spec.ts +138 -0
- package/tests/tsconfig.json +12 -0
- package/tsconfig.json +6 -10
package/README.md
CHANGED
|
@@ -1,526 +1,69 @@
|
|
|
1
1
|
# @owlmeans/client-auth
|
|
2
2
|
|
|
3
|
-
Client-side authentication
|
|
3
|
+
Client-side authentication service providing user auth state and external auth flow setup.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
- **Authentication Service**: Centralized authentication logic for client applications
|
|
12
|
-
- **React Components**: Pre-built authentication UI components
|
|
13
|
-
- **Module Integration**: Authentication modules for client-side routing and API calls
|
|
14
|
-
- **Manager Components**: Authentication manager UI for administrative interfaces
|
|
15
|
-
|
|
16
|
-
This package is part of the OwlMeans authentication quadra:
|
|
17
|
-
- **@owlmeans/auth**: Common authentication declarations and utilities
|
|
18
|
-
- **@owlmeans/auth-common**: Shared authentication logic
|
|
19
|
-
- **@owlmeans/client-auth**: Client-side authentication implementation *(this package)*
|
|
20
|
-
- **@owlmeans/server-auth**: Server-side authentication implementation
|
|
7
|
+
- `useSelfAuth()` — React hook that returns the current authenticated user's `Auth` object
|
|
8
|
+
- `setupExternalAuthentication()` — configure the client to authenticate against an external identity provider
|
|
9
|
+
- `modules` — pre-built client modules for the auth flow (login, dispatcher)
|
|
10
|
+
- `DEFAULT_ALIAS` — the auth service alias (`'auth'`)
|
|
21
11
|
|
|
22
12
|
## Installation
|
|
23
13
|
|
|
24
14
|
```bash
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Core Concepts
|
|
29
|
-
|
|
30
|
-
### Authentication Service
|
|
31
|
-
The authentication service manages the client-side authentication state, including token storage, validation, and user session management.
|
|
32
|
-
|
|
33
|
-
### Token Management
|
|
34
|
-
Client-side tokens are securely stored using the resource system and automatically attached to API requests for authentication.
|
|
35
|
-
|
|
36
|
-
### Resource-based Storage
|
|
37
|
-
Authentication data is persisted using the OwlMeans resource system, allowing for consistent data management across the application.
|
|
38
|
-
|
|
39
|
-
## API Reference
|
|
40
|
-
|
|
41
|
-
### Factory Functions
|
|
42
|
-
|
|
43
|
-
#### `makeAuthService(alias?: string): AuthService`
|
|
44
|
-
|
|
45
|
-
Creates a client-side authentication service instance.
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
49
|
-
|
|
50
|
-
const authService = makeAuthService('main-auth')
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Parameters:**
|
|
54
|
-
- `alias`: string (optional) - Service alias for registration, defaults to 'auth'
|
|
55
|
-
|
|
56
|
-
**Returns:** AuthService instance with client-specific capabilities
|
|
57
|
-
|
|
58
|
-
### Core Interfaces
|
|
59
|
-
|
|
60
|
-
#### `AuthService`
|
|
61
|
-
|
|
62
|
-
Main authentication service interface that extends the base AuthService from `@owlmeans/auth-common`.
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
interface AuthService extends InitializedService {
|
|
66
|
-
token?: string
|
|
67
|
-
auth?: Auth
|
|
68
|
-
|
|
69
|
-
// Authentication methods
|
|
70
|
-
authenticated(): Promise<string | null>
|
|
71
|
-
authenticate(token: AuthToken): Promise<void>
|
|
72
|
-
update(token?: string): Promise<void>
|
|
73
|
-
|
|
74
|
-
// Guard and handler methods
|
|
75
|
-
match(): Promise<boolean>
|
|
76
|
-
handle<T>(): Promise<T | void>
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
#### `ClientAuthRecord`
|
|
81
|
-
|
|
82
|
-
Interface for authentication data stored in client resources.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
interface ClientAuthRecord extends ResourceRecord {
|
|
86
|
-
token: string // Authentication token
|
|
87
|
-
profileId?: string // Optional profile identifier
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
#### `ClientAuthResource`
|
|
92
|
-
|
|
93
|
-
Resource interface for managing authentication data persistence.
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
interface ClientAuthResource extends ClientResource<ClientAuthRecord> {
|
|
97
|
-
// Inherits standard resource methods for CRUD operations
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
#### `AuthServiceAppend`
|
|
102
|
-
|
|
103
|
-
Interface for services that need authentication capabilities.
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
interface AuthServiceAppend {
|
|
107
|
-
auth(): AuthService
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Authentication Service Methods
|
|
112
|
-
|
|
113
|
-
#### `authenticated(): Promise<string | null>`
|
|
114
|
-
|
|
115
|
-
**Purpose**: Checks if the current session is authenticated and returns the auth token
|
|
116
|
-
|
|
117
|
-
**Behavior**:
|
|
118
|
-
- Checks for existing token in memory
|
|
119
|
-
- Falls back to loading token from persistent storage
|
|
120
|
-
- Validates token format and expiration
|
|
121
|
-
- Returns null if no valid authentication found
|
|
122
|
-
|
|
123
|
-
**Usage**: Primary method for checking authentication status
|
|
124
|
-
|
|
125
|
-
**Returns**: Promise that resolves to auth token string or null
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
const authService = makeAuthService()
|
|
129
|
-
|
|
130
|
-
const token = await authService.authenticated()
|
|
131
|
-
if (token) {
|
|
132
|
-
console.log('User is authenticated')
|
|
133
|
-
} else {
|
|
134
|
-
console.log('User needs to authenticate')
|
|
135
|
-
}
|
|
15
|
+
bun add @owlmeans/client-auth
|
|
136
16
|
```
|
|
137
17
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
**Purpose**: Authenticates the user with the provided token
|
|
141
|
-
|
|
142
|
-
**Behavior**:
|
|
143
|
-
- Calls the authentication dispatcher module with the token
|
|
144
|
-
- Stores the received authentication token
|
|
145
|
-
- Updates the authentication state
|
|
146
|
-
- Persists authentication data for future sessions
|
|
18
|
+
## Usage
|
|
147
19
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
**Parameters**:
|
|
151
|
-
- `token`: AuthToken - Authentication token received from login process
|
|
152
|
-
|
|
153
|
-
**Throws**: `AuthorizationError` if authentication fails
|
|
20
|
+
Access current auth state in a component:
|
|
154
21
|
|
|
155
22
|
```typescript
|
|
156
|
-
|
|
157
|
-
await authService.authenticate(loginToken)
|
|
158
|
-
console.log('Authentication successful')
|
|
159
|
-
} catch (error) {
|
|
160
|
-
console.error('Authentication failed:', error.message)
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
#### `update(token?: string): Promise<void>`
|
|
165
|
-
|
|
166
|
-
**Purpose**: Updates the authentication state with a new token
|
|
167
|
-
|
|
168
|
-
**Behavior**:
|
|
169
|
-
- If token is provided, stores it and updates authentication state
|
|
170
|
-
- If token is null/undefined, clears authentication state
|
|
171
|
-
- Updates persistent storage accordingly
|
|
172
|
-
- Parses token to extract Auth payload
|
|
173
|
-
|
|
174
|
-
**Usage**: Called to refresh authentication or clear session
|
|
175
|
-
|
|
176
|
-
**Parameters**:
|
|
177
|
-
- `token`: string (optional) - New authentication token, or undefined to clear
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
// Update with new token
|
|
181
|
-
await authService.update('Bearer new-auth-token')
|
|
182
|
-
|
|
183
|
-
// Clear authentication
|
|
184
|
-
await authService.update()
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
#### `match(): Promise<boolean>`
|
|
23
|
+
import { useSelfAuth } from '@owlmeans/client-auth'
|
|
188
24
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
**Usage**: Used by routing and module systems for access control
|
|
194
|
-
|
|
195
|
-
**Returns**: Promise that resolves to boolean indicating authentication status
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
const canAccess = await authService.match()
|
|
199
|
-
if (canAccess) {
|
|
200
|
-
// Allow access to protected resource
|
|
25
|
+
function UserMenu() {
|
|
26
|
+
const auth = useSelfAuth()
|
|
27
|
+
return <span>{auth?.userId}</span>
|
|
201
28
|
}
|
|
202
29
|
```
|
|
203
30
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
**Purpose**: Handler method for processing authenticated requests
|
|
207
|
-
|
|
208
|
-
**Behavior**: Currently returns undefined, can be extended for custom handling
|
|
209
|
-
|
|
210
|
-
**Usage**: Used by module system for request processing
|
|
211
|
-
|
|
212
|
-
**Returns**: Promise that resolves to undefined or custom result
|
|
213
|
-
|
|
214
|
-
### Module Functions
|
|
215
|
-
|
|
216
|
-
#### `elevate(modules: ClientModule[], alias: string): void`
|
|
217
|
-
|
|
218
|
-
Elevates authentication modules to client-side modules with enhanced capabilities.
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
import { elevate } from '@owlmeans/client-auth'
|
|
222
|
-
|
|
223
|
-
elevate(authModules, 'dispatcher-auth')
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
#### `setupExternalAuthentication(service: string): void`
|
|
227
|
-
|
|
228
|
-
Configures external authentication flow for a specific service.
|
|
31
|
+
Set up external authentication (e.g. OIDC redirect):
|
|
229
32
|
|
|
230
33
|
```typescript
|
|
231
34
|
import { setupExternalAuthentication } from '@owlmeans/client-auth'
|
|
232
35
|
|
|
233
|
-
|
|
36
|
+
// In context setup
|
|
37
|
+
setupExternalAuthentication(context, { serviceUrl: process.env.AUTH_URL })
|
|
234
38
|
```
|
|
235
39
|
|
|
236
|
-
|
|
40
|
+
## API
|
|
237
41
|
|
|
238
|
-
|
|
239
|
-
```typescript
|
|
240
|
-
const DEFAULT_ALIAS = 'auth' // Default service alias
|
|
241
|
-
const AUTH_RESOURCE = 'auth' // Resource identifier for auth data
|
|
242
|
-
const USER_ID = 'user' // Default user identifier
|
|
243
|
-
```
|
|
42
|
+
### `useSelfAuth(): Auth | null`
|
|
244
43
|
|
|
245
|
-
|
|
44
|
+
Returns the current `Auth` object from the context, or `null` if not authenticated.
|
|
246
45
|
|
|
247
|
-
|
|
46
|
+
### `setupExternalAuthentication(ctx, opts?)`
|
|
248
47
|
|
|
249
|
-
|
|
250
|
-
Located in `./components/dispatcher`, provides components for handling authentication flows.
|
|
48
|
+
Configures the context to redirect to an external identity provider for authentication.
|
|
251
49
|
|
|
252
|
-
|
|
253
|
-
Located in `./manager/components`, provides administrative interfaces for authentication management.
|
|
50
|
+
### `modules`
|
|
254
51
|
|
|
255
|
-
|
|
256
|
-
```typescript
|
|
257
|
-
import { /* components */ } from '@owlmeans/client-auth'
|
|
258
|
-
import { /* manager components */ } from '@owlmeans/client-auth/manager'
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### Manager Functionality
|
|
262
|
-
|
|
263
|
-
The package includes a manager subsystem accessible via `/manager` export:
|
|
264
|
-
|
|
265
|
-
```typescript
|
|
266
|
-
import { /* manager functions */ } from '@owlmeans/client-auth/manager'
|
|
267
|
-
import { /* manager modules */ } from '@owlmeans/client-auth/manager/modules'
|
|
268
|
-
import { /* manager plugins */ } from '@owlmeans/client-auth/manager/plugins'
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
The manager provides:
|
|
272
|
-
- Administrative authentication interfaces
|
|
273
|
-
- User management components
|
|
274
|
-
- Authentication flow configuration
|
|
275
|
-
- Plugin system for extending authentication capabilities
|
|
276
|
-
|
|
277
|
-
## Usage Examples
|
|
278
|
-
|
|
279
|
-
### Basic Authentication Setup
|
|
280
|
-
|
|
281
|
-
```typescript
|
|
282
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
283
|
-
import { makeClientContext } from '@owlmeans/client-context'
|
|
284
|
-
|
|
285
|
-
// Create context and auth service
|
|
286
|
-
const context = makeClientContext(config)
|
|
287
|
-
const authService = makeAuthService()
|
|
288
|
-
|
|
289
|
-
// Register the service
|
|
290
|
-
context.registerService(authService)
|
|
291
|
-
|
|
292
|
-
// Initialize context
|
|
293
|
-
await context.configure().init()
|
|
294
|
-
|
|
295
|
-
// Check authentication status
|
|
296
|
-
const isAuthenticated = await authService.authenticated()
|
|
297
|
-
console.log('Authenticated:', isAuthenticated != null)
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
### Authentication Flow
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
304
|
-
|
|
305
|
-
const authService = makeAuthService()
|
|
306
|
-
|
|
307
|
-
// Authenticate with token from login
|
|
308
|
-
const loginToken = { /* token from login process */ }
|
|
309
|
-
try {
|
|
310
|
-
await authService.authenticate(loginToken)
|
|
311
|
-
console.log('Successfully authenticated')
|
|
312
|
-
} catch (error) {
|
|
313
|
-
console.error('Authentication failed:', error)
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Check authentication status
|
|
317
|
-
const token = await authService.authenticated()
|
|
318
|
-
if (token) {
|
|
319
|
-
console.log('User is authenticated with token:', token)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Clear authentication
|
|
323
|
-
await authService.update()
|
|
324
|
-
console.log('Authentication cleared')
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Module Integration
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
import { modules, setupExternalAuthentication } from '@owlmeans/client-auth'
|
|
331
|
-
import { makeClientContext } from '@owlmeans/client-context'
|
|
332
|
-
|
|
333
|
-
const context = makeClientContext(config)
|
|
334
|
-
|
|
335
|
-
// Register authentication modules
|
|
336
|
-
context.registerModules(modules)
|
|
337
|
-
|
|
338
|
-
// Setup external authentication
|
|
339
|
-
setupExternalAuthentication('google-oauth')
|
|
340
|
-
|
|
341
|
-
// Initialize context
|
|
342
|
-
await context.configure().init()
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
### Protected Resource Access
|
|
346
|
-
|
|
347
|
-
```typescript
|
|
348
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
349
|
-
|
|
350
|
-
const authService = makeAuthService()
|
|
351
|
-
|
|
352
|
-
// Guard for protected resources
|
|
353
|
-
const canAccess = await authService.match()
|
|
354
|
-
if (!canAccess) {
|
|
355
|
-
throw new Error('Authentication required')
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Access protected resource
|
|
359
|
-
const protectedData = await api.getProtectedData()
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
### React Component Integration
|
|
363
|
-
|
|
364
|
-
```typescript
|
|
365
|
-
import React from 'react'
|
|
366
|
-
import { useContext } from 'react'
|
|
367
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
368
|
-
|
|
369
|
-
const AuthProvider = ({ children }) => {
|
|
370
|
-
const authService = makeAuthService()
|
|
371
|
-
|
|
372
|
-
const login = async (credentials) => {
|
|
373
|
-
try {
|
|
374
|
-
await authService.authenticate(credentials)
|
|
375
|
-
// Redirect to dashboard
|
|
376
|
-
} catch (error) {
|
|
377
|
-
// Handle login error
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
const logout = async () => {
|
|
382
|
-
await authService.update() // Clear authentication
|
|
383
|
-
// Redirect to login
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return (
|
|
387
|
-
<AuthContext.Provider value={{ authService, login, logout }}>
|
|
388
|
-
{children}
|
|
389
|
-
</AuthContext.Provider>
|
|
390
|
-
)
|
|
391
|
-
}
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
## Error Handling
|
|
395
|
-
|
|
396
|
-
The package uses the OwlMeans error system and may throw the following errors:
|
|
397
|
-
|
|
398
|
-
### `AuthorizationError`
|
|
399
|
-
Thrown when authentication fails or access is denied.
|
|
400
|
-
|
|
401
|
-
```typescript
|
|
402
|
-
import { AuthorizationError } from '@owlmeans/auth'
|
|
403
|
-
|
|
404
|
-
try {
|
|
405
|
-
await authService.authenticate(invalidToken)
|
|
406
|
-
} catch (error) {
|
|
407
|
-
if (error instanceof AuthorizationError) {
|
|
408
|
-
console.error('Authentication failed:', error.message)
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
Common scenarios:
|
|
414
|
-
- Invalid authentication token
|
|
415
|
-
- Expired token
|
|
416
|
-
- Insufficient permissions
|
|
417
|
-
- Network errors during authentication
|
|
418
|
-
|
|
419
|
-
## Resource Management
|
|
420
|
-
|
|
421
|
-
Authentication data is managed through the OwlMeans resource system:
|
|
422
|
-
|
|
423
|
-
```typescript
|
|
424
|
-
// Access the auth resource directly
|
|
425
|
-
const authResource = context.resource<ClientAuthResource>('auth')
|
|
426
|
-
|
|
427
|
-
// Load stored authentication data
|
|
428
|
-
const authRecord = await authResource.load('user')
|
|
429
|
-
|
|
430
|
-
// Save authentication data
|
|
431
|
-
await authResource.save({
|
|
432
|
-
id: 'user',
|
|
433
|
-
token: 'Bearer auth-token-here',
|
|
434
|
-
profileId: 'user-profile-123'
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
// Clear authentication data
|
|
438
|
-
await authResource.delete('user')
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
## Integration with Other Packages
|
|
442
|
-
|
|
443
|
-
### Authentication Quadra Integration
|
|
444
|
-
|
|
445
|
-
```typescript
|
|
446
|
-
// Common authentication (shared)
|
|
447
|
-
import { AuthRole, AuthenticationType } from '@owlmeans/auth'
|
|
448
|
-
|
|
449
|
-
// Shared authentication logic
|
|
450
|
-
import { authMiddleware } from '@owlmeans/auth-common'
|
|
451
|
-
|
|
452
|
-
// Client authentication (this package)
|
|
453
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
454
|
-
|
|
455
|
-
// Server authentication (backend)
|
|
456
|
-
import { makeServerAuthService } from '@owlmeans/server-auth'
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
### Context Integration
|
|
460
|
-
|
|
461
|
-
```typescript
|
|
462
|
-
import { makeClientContext } from '@owlmeans/client-context'
|
|
463
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
464
|
-
|
|
465
|
-
const context = makeClientContext(config)
|
|
466
|
-
const authService = makeAuthService()
|
|
467
|
-
|
|
468
|
-
context.registerService(authService)
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
### Module Integration
|
|
472
|
-
|
|
473
|
-
```typescript
|
|
474
|
-
import { modules } from '@owlmeans/client-auth'
|
|
475
|
-
import { makeClientContext } from '@owlmeans/client-context'
|
|
476
|
-
|
|
477
|
-
const context = makeClientContext(config)
|
|
478
|
-
context.registerModules(modules)
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
### Flow Integration
|
|
482
|
-
|
|
483
|
-
```typescript
|
|
484
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
485
|
-
import { FlowService } from '@owlmeans/client-flow'
|
|
486
|
-
|
|
487
|
-
// Authentication can be integrated with user flows
|
|
488
|
-
const authService = makeAuthService()
|
|
489
|
-
const flowService = context.service<FlowService>('flow')
|
|
490
|
-
|
|
491
|
-
// Use authentication in flow steps
|
|
492
|
-
await flowService.addStep('authenticate', async () => {
|
|
493
|
-
const isAuth = await authService.authenticated()
|
|
494
|
-
if (!isAuth) {
|
|
495
|
-
throw new Error('Authentication required')
|
|
496
|
-
}
|
|
497
|
-
})
|
|
498
|
-
```
|
|
52
|
+
Pre-built `ClientModule[]` for the auth flow (mirrors `@owlmeans/auth-common`'s modules with client route models).
|
|
499
53
|
|
|
500
|
-
|
|
54
|
+
### `DEFAULT_ALIAS`
|
|
501
55
|
|
|
502
|
-
|
|
503
|
-
2. **Context Registration**: Always register the authentication service with the application context
|
|
504
|
-
3. **Error Handling**: Implement proper error handling for authentication failures
|
|
505
|
-
4. **Token Security**: Let the service handle token storage and validation
|
|
506
|
-
5. **Module Integration**: Use provided modules for consistent authentication flows
|
|
507
|
-
6. **Manager Access**: Use manager components for administrative authentication features
|
|
56
|
+
Auth service alias: `'auth'`.
|
|
508
57
|
|
|
509
|
-
##
|
|
58
|
+
## Product-Viable Integration Notes
|
|
510
59
|
|
|
511
|
-
|
|
512
|
-
- `@owlmeans/auth`
|
|
513
|
-
-
|
|
514
|
-
-
|
|
515
|
-
- `@owlmeans/client-module` - Client-side module system
|
|
516
|
-
- `@owlmeans/client-resource` - Client-side resource management
|
|
517
|
-
- `@owlmeans/basic-envelope` - Token envelope handling
|
|
518
|
-
- `@owlmeans/context` - Core context system
|
|
60
|
+
- The manager web app imports `DEFAULT_ALIAS` from this package as the client-side guard alias.
|
|
61
|
+
- `@owlmeans/web-oidc-rp/auth/plugins` is imported for side effects to register the `OIDC_CLIENT_AUTH` and `GOOGLE_CLIENT_AUTH` plugins.
|
|
62
|
+
- Redirect plugins persist auth control state before leaving the app and restore it before submitting provider query params as `AuthCredentials`.
|
|
63
|
+
- After login, the browser stores a normal OwlMeans bearer token; product authorization is enforced by server gates and handler checks.
|
|
519
64
|
|
|
520
65
|
## Related Packages
|
|
521
66
|
|
|
522
|
-
- [`@owlmeans/auth`](../auth)
|
|
523
|
-
- [`@owlmeans/auth-common`](../auth-common)
|
|
524
|
-
- [`@owlmeans/server-auth`](../server-auth)
|
|
525
|
-
- [`@owlmeans/client-context`](../client-context) - Client context management
|
|
526
|
-
- [`@owlmeans/client-module`](../client-module) - Client module system
|
|
67
|
+
- [`@owlmeans/auth`](../auth) — `Auth` type returned by `useSelfAuth`
|
|
68
|
+
- [`@owlmeans/auth-common`](../auth-common) — auth module route definitions
|
|
69
|
+
- [`@owlmeans/server-auth`](../server-auth) — server-side counterpart
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/components/dispatcher/component.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGxD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,CAAC,MAAM,aAAa,GAAmB,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;IACtG,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,EAA0B,CAAA;IAEtE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C,IAAI,CAAC,KAAK,IAAI,EAAE;oBAClD,OAAO,MAAM,QAAQ,EAAE,CAAA;gBACzB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAQ,EAAE,EAAE;oBACpB,oCAAoC;oBACpC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBAClB,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAA;IAEvB,MAAM,YAAY,GAAG,WAAW,CAA0C,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACzF,aAAa,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACjC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,KAAC,QAAQ,IAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAAA;AACrE,CAAC,CAAA"}
|
|
@@ -2,7 +2,7 @@ import type { FC, PropsWithChildren } from 'react';
|
|
|
2
2
|
import type { RoutedComponent } from '@owlmeans/client';
|
|
3
3
|
import type { AuthToken } from '@owlmeans/auth';
|
|
4
4
|
import type { ClientContext, ClientConfig } from '@owlmeans/client-context';
|
|
5
|
-
import type { AbstractRequest } from '@owlmeans/
|
|
5
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint';
|
|
6
6
|
import type { FlowPayload } from '@owlmeans/flow';
|
|
7
7
|
export interface DispatcherProps {
|
|
8
8
|
alias: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/dispatcher/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,K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|
1
|
-
import type {
|
|
2
|
-
import type { AbstractRequest } from '@owlmeans/
|
|
3
|
-
export declare const useWs: (module: string |
|
|
1
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint';
|
|
2
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint';
|
|
3
|
+
export declare const useWs: (module: string | ClientEntrypoint<any>, _request?: Partial<AbstractRequest<any>>) => import("@owlmeans/socket").Connection | null;
|
|
4
4
|
export declare const useSelfAuth: (force?: boolean) => boolean;
|
|
5
5
|
//# sourceMappingURL=helper.d.ts.map
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAGnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAS3D,eAAO,MAAM,KAAK,GAChB,QAAQ,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,EAAE,WAAW,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,iDA2BjF,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAO,OAAc,YAoBhD,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useNavigate } from '@owlmeans/client';
|
|
2
|
-
import { provideRequest } from '@owlmeans/client-
|
|
2
|
+
import { provideRequest } from '@owlmeans/client-entrypoint';
|
|
3
3
|
import { useWs as useWebSocket } from '@owlmeans/client-socket';
|
|
4
4
|
import { useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import { AUTH_QUERY, DISPATCHER } from '@owlmeans/auth';
|
|
@@ -8,7 +8,7 @@ import { AUTH_QUERY, DISPATCHER } from '@owlmeans/auth';
|
|
|
8
8
|
// import { OidcAuthStep } from '@owlmeans/flow'
|
|
9
9
|
export const useWs = (module, _request) => {
|
|
10
10
|
const ctx = useContext();
|
|
11
|
-
const mod = useMemo(() => typeof module === 'string' ? ctx.
|
|
11
|
+
const mod = useMemo(() => typeof module === 'string' ? ctx.entrypoint(module) : module, [module]);
|
|
12
12
|
const request = useMemo(() => {
|
|
13
13
|
if (_request == null) {
|
|
14
14
|
_request = provideRequest(mod.getAlias(), mod.getPath());
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAG/D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACvD,+CAA+C;AAC/C,+CAA+C;AAC/C,gDAAgD;AAEhD,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAsC,EAAE,QAAwC,EAChF,EAAE;IACF,MAAM,GAAG,GAAG,UAAU,EAAkD,CAAA;IAExE,MAAM,GAAG,GAAG,OAAO,CACjB,GAAG,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAmB,MAAM,CAAC,CAAC,CAAC,CAAC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K,IAAI,CAAC,IAAI,EAAE,CAAC;gBACnB,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,CAAA;gBAClB,6BAA6B;gBAC7B,qEAAqE;YACvE,CAAC;YAED,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
|
|
@@ -2,7 +2,7 @@ import { ALL_SCOPES, AUTHEN_AUTHEN, AUTHEN_INIT, AuthRole, AuthenticationStage,
|
|
|
2
2
|
import { AuthenCredError } from '../../errors.js';
|
|
3
3
|
import { plugins } from '../../plugins/index.js';
|
|
4
4
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope';
|
|
5
|
-
import {
|
|
5
|
+
import { EntrypointOutcome } from '@owlmeans/entrypoint';
|
|
6
6
|
import { DEFAULT_ALIAS as FLOW_SERVICE, FLOW_STATE } from '@owlmeans/client-flow';
|
|
7
7
|
import { CONTROL_STATE_ID } from './consts.js';
|
|
8
8
|
import { ResilientError } from '@owlmeans/error';
|
|
@@ -22,7 +22,7 @@ export const makeControl = (context, callback) => {
|
|
|
22
22
|
control.type = control.request.type;
|
|
23
23
|
control.beforeAuthenticate = plugins[control.type].beforeAuthenticate;
|
|
24
24
|
control.afterAuthenticate = plugins[control.type].afterAuthenticate;
|
|
25
|
-
const module = context.
|
|
25
|
+
const module = context.entrypoint(AUTHEN_INIT);
|
|
26
26
|
const [allowance] = await module.call({ body: control.request });
|
|
27
27
|
control.allowance = allowance;
|
|
28
28
|
control.updateStage(AuthenticationStage.Authenticate);
|
|
@@ -56,9 +56,9 @@ export const makeControl = (context, callback) => {
|
|
|
56
56
|
}
|
|
57
57
|
// We return back unwrapped challenge
|
|
58
58
|
credentials.challenge = control.allowance?.challenge;
|
|
59
|
-
const [token, status] = await context.
|
|
59
|
+
const [token, status] = await context.entrypoint(AUTHEN_AUTHEN)
|
|
60
60
|
.call({ body: credentials });
|
|
61
|
-
if (status ===
|
|
61
|
+
if (status === EntrypointOutcome.Ok && token.token != null
|
|
62
62
|
&& token.token !== '' && control.afterAuthenticate != null) {
|
|
63
63
|
const resultingCred = makeEnvelopeModel(token.token, EnvelopeKind.Token).message();
|
|
64
64
|
await control.afterAuthenticate(resultingCred, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../../../src/manager/components/authentication/control.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,mBAAmB,EAAE,kBAAkB,GAC1F,MAAM,gBAAgB,CAAA;AAKvB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../../../src/manager/components/authentication/control.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,mBAAmB,EAAE,kBAAkB,GAC1F,MAAM,gBAAgB,CAAA;AAKvB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;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C,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const modules: import("@owlmeans/
|
|
1
|
+
export declare const modules: import("@owlmeans/entrypoint").CommonEntrypoint[];
|
|
2
2
|
//# sourceMappingURL=modules.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/manager/modules.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/manager/modules.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,OAAO,mDAAO,CAAA"}
|
package/build/manager/modules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AUTHEN, AUTHEN_AUTHEN, AUTHEN_INIT, AUTHEN_RELY, CAUTHEN, CAUTHEN_AUTHEN, CAUTHEN_AUTHEN_DEFAULT, CAUTHEN_AUTHEN_TYPED, DISPATCHER } from '@owlmeans/auth';
|
|
2
2
|
import { modules as list } from '@owlmeans/auth-common';
|
|
3
3
|
import { handler } from '@owlmeans/client';
|
|
4
|
-
import { elevate, stab } from '@owlmeans/client-
|
|
4
|
+
import { elevate, stab } from '@owlmeans/client-entrypoint';
|
|
5
5
|
import { AuthenticationHOC } from './components/authentication/component.js';
|
|
6
6
|
elevate(list, AUTHEN);
|
|
7
7
|
elevate(list, AUTHEN_INIT, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../../src/manager/modules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACnK,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,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|
2
|
-
export declare const modules:
|
|
1
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint';
|
|
2
|
+
export declare const modules: ClientEntrypoint[];
|
|
3
3
|
export declare const setupExternalAuthentication: (service: string) => void;
|
|
4
4
|
//# 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":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAInE,eAAO,MAAM,OAAO,EAAE,gBAAgB,EAA+B,CAAA;AAErE,eAAO,MAAM,2BAA2B,GAAI,SAAS,MAAM,SAE1D,CAAA"}
|
package/build/modules.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { elevate, stab } from '@owlmeans/client-
|
|
1
|
+
import { elevate, stab } from '@owlmeans/client-entrypoint';
|
|
2
2
|
import { modules as list } from '@owlmeans/auth-common';
|
|
3
3
|
import { CAUTHEN_FLOW_ENTER, DISPATCHER_AUTHEN } from '@owlmeans/auth';
|
|
4
4
|
elevate(list, DISPATCHER_AUTHEN);
|
package/build/modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGtE,OAAO,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AAEhC,MAAM,CAAC,MAAM,OAAO,GAAuB,IAA0B,CAAA;AAErE,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,OAAe,EAAE,EAAE;IAC7D,OAAO,CAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;AACvF,CAAC,CAAA"}
|
package/build/service.js
CHANGED
|
@@ -12,7 +12,7 @@ export const makeAuthService = (alias = DEFAULT_ALIAS) => {
|
|
|
12
12
|
},
|
|
13
13
|
authenticate: async (token) => {
|
|
14
14
|
const context = assertContext(service.ctx, location);
|
|
15
|
-
const [authToken] = await context.
|
|
15
|
+
const [authToken] = await context.entrypoint(DISPATCHER_AUTHEN)
|
|
16
16
|
.call({ body: token });
|
|
17
17
|
await service.update(authToken.token);
|
|
18
18
|
},
|
package/build/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGtE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAgB,aAAa,EAAe,EAAE;IAC5E,MAAM,QAAQ,GAAG,gBAAgB,KAAK,EAAE,CAAA;IACxC,MAAM,OAAO,GAAgB,aA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AAG,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE/C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/client-auth",
|
|
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 66 && 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",
|
|
@@ -42,24 +43,24 @@
|
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"@owlmeans/auth": "^0.1.
|
|
46
|
-
"@owlmeans/auth-common": "^0.1.
|
|
47
|
-
"@owlmeans/basic-envelope": "^0.1.
|
|
48
|
-
"@owlmeans/basic-keys": "^0.1.
|
|
49
|
-
"@owlmeans/client": "^0.1.
|
|
50
|
-
"@owlmeans/client-context": "^0.1.
|
|
51
|
-
"@owlmeans/client-flow": "^0.1.
|
|
52
|
-
"@owlmeans/client-
|
|
53
|
-
"@owlmeans/client-resource": "^0.1.
|
|
54
|
-
"@owlmeans/client-socket": "^0.1.
|
|
55
|
-
"@owlmeans/context": "^0.1.
|
|
56
|
-
"@owlmeans/did": "^0.1.
|
|
57
|
-
"@owlmeans/error": "^0.1.
|
|
58
|
-
"@owlmeans/flow": "^0.1.
|
|
59
|
-
"@owlmeans/
|
|
60
|
-
"@owlmeans/resource": "^0.1.
|
|
61
|
-
"@owlmeans/socket": "^0.1.
|
|
62
|
-
"@owlmeans/web-flow": "^0.1.
|
|
46
|
+
"@owlmeans/auth": "^0.1.4",
|
|
47
|
+
"@owlmeans/auth-common": "^0.1.4",
|
|
48
|
+
"@owlmeans/basic-envelope": "^0.1.4",
|
|
49
|
+
"@owlmeans/basic-keys": "^0.1.4",
|
|
50
|
+
"@owlmeans/client": "^0.1.4",
|
|
51
|
+
"@owlmeans/client-context": "^0.1.4",
|
|
52
|
+
"@owlmeans/client-flow": "^0.1.4",
|
|
53
|
+
"@owlmeans/client-entrypoint": "^0.1.4",
|
|
54
|
+
"@owlmeans/client-resource": "^0.1.4",
|
|
55
|
+
"@owlmeans/client-socket": "^0.1.4",
|
|
56
|
+
"@owlmeans/context": "^0.1.4",
|
|
57
|
+
"@owlmeans/did": "^0.1.4",
|
|
58
|
+
"@owlmeans/error": "^0.1.4",
|
|
59
|
+
"@owlmeans/flow": "^0.1.4",
|
|
60
|
+
"@owlmeans/entrypoint": "^0.1.4",
|
|
61
|
+
"@owlmeans/resource": "^0.1.4",
|
|
62
|
+
"@owlmeans/socket": "^0.1.4",
|
|
63
|
+
"@owlmeans/web-flow": "^0.1.4",
|
|
63
64
|
"@scure/base": "^1.1.9"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
@@ -67,10 +68,13 @@
|
|
|
67
68
|
"react": "*"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
71
|
+
"@owlmeans/dep-config": "workspace:*",
|
|
72
|
+
"@owlmeans/test-auth": "^0.1.4",
|
|
73
|
+
"@types/bun": "^1.3.0",
|
|
70
74
|
"@types/react": "^19.2.7",
|
|
71
75
|
"nodemon": "^3.1.11",
|
|
72
76
|
"npm-check": "^6.0.1",
|
|
73
|
-
"typescript": "^
|
|
77
|
+
"typescript": "^6.0.2"
|
|
74
78
|
},
|
|
75
79
|
"publishConfig": {
|
|
76
80
|
"access": "public"
|
|
@@ -2,12 +2,12 @@ import { useCallback, useEffect, useState } from 'react'
|
|
|
2
2
|
import type { DispatcherRendererProps, TDispatcherHOC } from './types.js'
|
|
3
3
|
import type { AuthToken } from '@owlmeans/auth'
|
|
4
4
|
import { AUTH_QUERY, DISPATCHER } from '@owlmeans/auth'
|
|
5
|
-
import type {
|
|
5
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
6
6
|
import { HOME } from '@owlmeans/context'
|
|
7
7
|
import { DEFAULT_ALIAS, DEFAULT_ENTITY } from '../../consts.js'
|
|
8
8
|
import type { AuthService } from '@owlmeans/auth-common'
|
|
9
9
|
import { useNavigate } from '@owlmeans/client'
|
|
10
|
-
import type { AbstractRequest } from '@owlmeans/
|
|
10
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
11
11
|
import type { FlowService } from '@owlmeans/client-flow'
|
|
12
12
|
import { DEFAULT_ALIAS as FLOW_SERVICE } from '@owlmeans/client-flow'
|
|
13
13
|
import { FLOW_PLACEHOLDER, OidcAuthStep, STD_OIDC_FLOW } from '@owlmeans/flow'
|
|
@@ -19,7 +19,7 @@ export const DispatcherHOC: TDispatcherHOC = Renderer => ({ context, params, ali
|
|
|
19
19
|
const navigator = useNavigate()
|
|
20
20
|
const navigate = useCallback(async () => {
|
|
21
21
|
alias = alias == null || alias === DISPATCHER ? HOME : alias
|
|
22
|
-
const module = context.module<
|
|
22
|
+
const module = context.module<ClientEntrypoint<string>>(alias)
|
|
23
23
|
if (alias === HOME) {
|
|
24
24
|
params = {}
|
|
25
25
|
query = {}
|
|
@@ -2,7 +2,7 @@ import type { FC, PropsWithChildren } from 'react'
|
|
|
2
2
|
import type { RoutedComponent } from '@owlmeans/client'
|
|
3
3
|
import type { AuthToken } from '@owlmeans/auth'
|
|
4
4
|
import type { ClientContext, ClientConfig } from '@owlmeans/client-context'
|
|
5
|
-
import type { AbstractRequest } from '@owlmeans/
|
|
5
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
6
6
|
import type { FlowPayload } from '@owlmeans/flow'
|
|
7
7
|
|
|
8
8
|
export interface DispatcherProps {
|
package/src/helper.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useContext, useNavigate } from '@owlmeans/client'
|
|
2
|
-
import type {
|
|
3
|
-
import { provideRequest } from '@owlmeans/client-
|
|
2
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
3
|
+
import { provideRequest } from '@owlmeans/client-entrypoint'
|
|
4
4
|
import { useWs as useWebSocket } from '@owlmeans/client-socket'
|
|
5
|
-
import type { AbstractRequest } from '@owlmeans/
|
|
5
|
+
import type { AbstractRequest } from '@owlmeans/entrypoint'
|
|
6
6
|
import type { AuthServiceAppend } from './types.js'
|
|
7
7
|
import { useEffect, useMemo, useState } from 'react'
|
|
8
8
|
import type { ClientContext } from '@owlmeans/client-context'
|
|
@@ -12,12 +12,12 @@ import { AUTH_QUERY, DISPATCHER } from '@owlmeans/auth'
|
|
|
12
12
|
// import { OidcAuthStep } from '@owlmeans/flow'
|
|
13
13
|
|
|
14
14
|
export const useWs = (
|
|
15
|
-
module: string |
|
|
15
|
+
module: string | ClientEntrypoint<any>, _request?: Partial<AbstractRequest<any>>
|
|
16
16
|
) => {
|
|
17
17
|
const ctx = useContext() as unknown as AuthServiceAppend & ClientContext
|
|
18
18
|
|
|
19
19
|
const mod = useMemo(
|
|
20
|
-
() => typeof module === 'string' ? ctx.
|
|
20
|
+
() => typeof module === 'string' ? ctx.entrypoint<ClientEntrypoint>(module) : module, [module]
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
const request = useMemo(() => {
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
import type { AllowanceResponse, AllowanceRequest, AuthToken, AuthCredentials } from '@owlmeans/auth'
|
|
6
6
|
import type { ClientContext } from '@owlmeans/client'
|
|
7
7
|
import type { ClientConfig } from '@owlmeans/client-context'
|
|
8
|
-
import type {
|
|
8
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
9
9
|
import { AuthenCredError } from '../../errors.js'
|
|
10
10
|
import { plugins } from '../../plugins/index.js'
|
|
11
11
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
12
12
|
import type { EnvelopeModel } from '@owlmeans/basic-envelope'
|
|
13
|
-
import {
|
|
13
|
+
import { EntrypointOutcome } from '@owlmeans/entrypoint'
|
|
14
14
|
import { DEFAULT_ALIAS as FLOW_SERVICE, FLOW_STATE } from '@owlmeans/client-flow'
|
|
15
15
|
import type { FlowService, StateResource } from '@owlmeans/client-flow'
|
|
16
16
|
import { CONTROL_STATE_ID } from './consts.js'
|
|
@@ -44,7 +44,7 @@ export const makeControl = (
|
|
|
44
44
|
control.beforeAuthenticate = plugins[control.type].beforeAuthenticate
|
|
45
45
|
control.afterAuthenticate = plugins[control.type].afterAuthenticate
|
|
46
46
|
|
|
47
|
-
const module = context.
|
|
47
|
+
const module = context.entrypoint<ClientEntrypoint<AllowanceResponse>>(AUTHEN_INIT)
|
|
48
48
|
const [allowance] = await module.call({ body: control.request })
|
|
49
49
|
|
|
50
50
|
control.allowance = allowance
|
|
@@ -89,10 +89,10 @@ export const makeControl = (
|
|
|
89
89
|
// We return back unwrapped challenge
|
|
90
90
|
credentials.challenge = control.allowance?.challenge
|
|
91
91
|
|
|
92
|
-
const [token, status] = await context.
|
|
92
|
+
const [token, status] = await context.entrypoint<ClientEntrypoint<AuthToken>>(AUTHEN_AUTHEN)
|
|
93
93
|
.call({ body: credentials })
|
|
94
94
|
|
|
95
|
-
if (status ===
|
|
95
|
+
if (status === EntrypointOutcome.Ok && token.token != null
|
|
96
96
|
&& token.token !== '' && control.afterAuthenticate != null) {
|
|
97
97
|
const resultingCred = makeEnvelopeModel<AuthCredentials>(token.token, EnvelopeKind.Token).message()
|
|
98
98
|
await control.afterAuthenticate(resultingCred, context)
|
package/src/manager/modules.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { AUTHEN, AUTHEN_AUTHEN, AUTHEN_INIT, AUTHEN_RELY, CAUTHEN, CAUTHEN_AUTHEN, CAUTHEN_AUTHEN_DEFAULT, CAUTHEN_AUTHEN_TYPED, DISPATCHER } from '@owlmeans/auth'
|
|
3
3
|
import { modules as list } from '@owlmeans/auth-common'
|
|
4
4
|
import { handler } from '@owlmeans/client'
|
|
5
|
-
import { elevate, stab } from '@owlmeans/client-
|
|
5
|
+
import { elevate, stab } from '@owlmeans/client-entrypoint'
|
|
6
6
|
import { AuthenticationHOC } from './components/authentication/component.js'
|
|
7
7
|
|
|
8
8
|
elevate(list, AUTHEN)
|
package/src/modules.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
import { elevate, stab } from '@owlmeans/client-
|
|
2
|
+
import { elevate, stab } from '@owlmeans/client-entrypoint'
|
|
3
3
|
import { modules as list } from '@owlmeans/auth-common'
|
|
4
4
|
import { CAUTHEN_FLOW_ENTER, DISPATCHER_AUTHEN } from '@owlmeans/auth'
|
|
5
|
-
import type {
|
|
5
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
6
6
|
|
|
7
7
|
elevate(list, DISPATCHER_AUTHEN)
|
|
8
8
|
|
|
9
|
-
export const modules:
|
|
9
|
+
export const modules: ClientEntrypoint[] = list as ClientEntrypoint[]
|
|
10
10
|
|
|
11
11
|
export const setupExternalAuthentication = (service: string) => {
|
|
12
12
|
elevate(list, CAUTHEN_FLOW_ENTER, stab, { routeOptions: { overrides: { service } } })
|
package/src/service.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { assertContext, createService } from '@owlmeans/context'
|
|
|
5
5
|
import type { ClientContext, ClientConfig } from '@owlmeans/client-context'
|
|
6
6
|
import { AuthorizationError, DISPATCHER_AUTHEN } from '@owlmeans/auth'
|
|
7
7
|
import type { Auth, AuthToken } from '@owlmeans/auth'
|
|
8
|
-
import type {
|
|
8
|
+
import type { ClientEntrypoint } from '@owlmeans/client-entrypoint'
|
|
9
9
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
10
10
|
import { authMiddleware } from '@owlmeans/auth-common'
|
|
11
11
|
|
|
@@ -21,7 +21,7 @@ export const makeAuthService = (alias: string = DEFAULT_ALIAS): AuthService => {
|
|
|
21
21
|
authenticate: async token => {
|
|
22
22
|
const context = assertContext(service.ctx, location)
|
|
23
23
|
|
|
24
|
-
const [authToken] = await context.
|
|
24
|
+
const [authToken] = await context.entrypoint<ClientEntrypoint<AuthToken>>(DISPATCHER_AUTHEN)
|
|
25
25
|
.call({ body: token })
|
|
26
26
|
|
|
27
27
|
await service.update(authToken.token)
|
package/tests/context.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
|
|
2
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context'
|
|
3
|
+
import { createStaticResource } from '@owlmeans/static-resource'
|
|
4
|
+
import { AUTH_RESOURCE, DEFAULT_ALIAS } from '../src/consts.js'
|
|
5
|
+
import { makeAuthService } from '../src/service.js'
|
|
6
|
+
|
|
7
|
+
const RESOURCE_KEY = 'client-auth-test-store'
|
|
8
|
+
|
|
9
|
+
export const makeTestContext = () => {
|
|
10
|
+
const cfg: BasicConfig = {
|
|
11
|
+
ready: false,
|
|
12
|
+
service: 'client-auth-tests',
|
|
13
|
+
layer: Layer.Application,
|
|
14
|
+
type: AppType.Frontend,
|
|
15
|
+
services: {},
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const context = makeBasicContext(cfg) as BasicContext<BasicConfig>
|
|
19
|
+
|
|
20
|
+
// AUTH_RESOURCE stores the bearer token record
|
|
21
|
+
context.registerResource(createStaticResource(AUTH_RESOURCE, RESOURCE_KEY))
|
|
22
|
+
|
|
23
|
+
// Register client auth service
|
|
24
|
+
context.registerService(makeAuthService(DEFAULT_ALIAS))
|
|
25
|
+
|
|
26
|
+
return context
|
|
27
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, test, expect } from 'bun:test'
|
|
2
|
+
import { makeTestContext } from './context.js'
|
|
3
|
+
import { makeFixtureKeyPair } from '@owlmeans/test-auth'
|
|
4
|
+
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
5
|
+
import { AuthorizationError, AuthroizationType, AuthRole } from '@owlmeans/auth'
|
|
6
|
+
import type { Auth } from '@owlmeans/auth'
|
|
7
|
+
import { DEFAULT_ALIAS, AUTH_RESOURCE, USER_ID } from '../src/consts.js'
|
|
8
|
+
import type { AuthService } from '@owlmeans/auth-common'
|
|
9
|
+
import type { Resource } from '@owlmeans/resource'
|
|
10
|
+
import type { ClientAuthRecord } from '../src/types.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Produce a valid bearer token (as server-auth would issue)
|
|
14
|
+
*/
|
|
15
|
+
const makeBearer = async (auth: Partial<Auth>) => {
|
|
16
|
+
const appKP = makeFixtureKeyPair('client-auth-app-key')
|
|
17
|
+
const fullAuth: Auth = {
|
|
18
|
+
token: 'nonce-123',
|
|
19
|
+
userId: 'user-1',
|
|
20
|
+
scopes: ['*'],
|
|
21
|
+
role: AuthRole.User,
|
|
22
|
+
type: AuthroizationType.Ed25519BasicToken,
|
|
23
|
+
source: 'test-service',
|
|
24
|
+
isUser: true,
|
|
25
|
+
createdAt: new Date(),
|
|
26
|
+
...auth,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const signed = await makeEnvelopeModel<Auth>(AuthroizationType.Ed25519BasicToken)
|
|
30
|
+
.send(fullAuth, null).sign(appKP, EnvelopeKind.Token)
|
|
31
|
+
|
|
32
|
+
return `${AuthroizationType.Ed25519BasicToken.toUpperCase()} ${signed}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const initContext = async () => {
|
|
36
|
+
const context = makeTestContext()
|
|
37
|
+
context.configure()
|
|
38
|
+
await context.init()
|
|
39
|
+
return context
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('@owlmeans/client-auth — update', () => {
|
|
43
|
+
test('stores token and parses Auth from bearer', async () => {
|
|
44
|
+
const context = await initContext()
|
|
45
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
46
|
+
|
|
47
|
+
const bearer = await makeBearer({ userId: 'user-update-test', scopes: ['read'] })
|
|
48
|
+
await authService.update(bearer)
|
|
49
|
+
|
|
50
|
+
// Token should be stored in memory
|
|
51
|
+
expect(authService.token).toBe(bearer)
|
|
52
|
+
|
|
53
|
+
// Auth should be parsed from the envelope
|
|
54
|
+
expect(authService.auth).not.toBeUndefined()
|
|
55
|
+
expect(authService.auth!.userId).toBe('user-update-test')
|
|
56
|
+
expect(authService.auth!.scopes).toEqual(['read'])
|
|
57
|
+
|
|
58
|
+
// Token should be persisted in the resource store
|
|
59
|
+
const store = context.resource<Resource<ClientAuthRecord>>(AUTH_RESOURCE)
|
|
60
|
+
const record = await store.load(USER_ID)
|
|
61
|
+
expect(record).not.toBeNull()
|
|
62
|
+
expect(record!.token).toBe(bearer)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('clears auth when token is null', async () => {
|
|
66
|
+
const context = await initContext()
|
|
67
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
68
|
+
|
|
69
|
+
// First set a valid token
|
|
70
|
+
const bearer = await makeBearer({ userId: 'user-to-clear' })
|
|
71
|
+
await authService.update(bearer)
|
|
72
|
+
expect(authService.auth).not.toBeUndefined()
|
|
73
|
+
|
|
74
|
+
// Now clear it
|
|
75
|
+
await authService.update(null as any)
|
|
76
|
+
|
|
77
|
+
expect(authService.token).toBeNull()
|
|
78
|
+
expect(authService.auth).toBeUndefined()
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('@owlmeans/client-auth — authenticated', () => {
|
|
83
|
+
test('returns null when no token exists', async () => {
|
|
84
|
+
const context = await initContext()
|
|
85
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
86
|
+
|
|
87
|
+
const result = await authService.authenticated()
|
|
88
|
+
expect(result).toBeNull()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('loads token from storage on first call', async () => {
|
|
92
|
+
const context = await initContext()
|
|
93
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
94
|
+
|
|
95
|
+
// Pre-populate storage directly (simulating previous session)
|
|
96
|
+
const bearer = await makeBearer({ userId: 'persisted-user' })
|
|
97
|
+
const store = context.resource<Resource<ClientAuthRecord>>(AUTH_RESOURCE)
|
|
98
|
+
await store.create({ id: USER_ID, token: bearer })
|
|
99
|
+
|
|
100
|
+
// Now call authenticated — it should load from store
|
|
101
|
+
const result = await authService.authenticated()
|
|
102
|
+
expect(result).toBe(bearer)
|
|
103
|
+
expect(authService.auth).not.toBeUndefined()
|
|
104
|
+
expect(authService.auth!.userId).toBe('persisted-user')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('returns in-memory token without re-reading storage', async () => {
|
|
108
|
+
const context = await initContext()
|
|
109
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
110
|
+
|
|
111
|
+
const bearer = await makeBearer({ userId: 'memory-user' })
|
|
112
|
+
await authService.update(bearer)
|
|
113
|
+
|
|
114
|
+
const result = await authService.authenticated()
|
|
115
|
+
expect(result).toBe(bearer)
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('@owlmeans/client-auth — user', () => {
|
|
120
|
+
test('throws AuthorizationError when not authenticated', async () => {
|
|
121
|
+
const context = await initContext()
|
|
122
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
123
|
+
|
|
124
|
+
expect(() => authService.user()).toThrow(AuthorizationError)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('returns Auth after update', async () => {
|
|
128
|
+
const context = await initContext()
|
|
129
|
+
const authService = context.service<AuthService>(DEFAULT_ALIAS)
|
|
130
|
+
|
|
131
|
+
const bearer = await makeBearer({ userId: 'user-for-user-call', role: AuthRole.Guest })
|
|
132
|
+
await authService.update(bearer)
|
|
133
|
+
|
|
134
|
+
const auth = authService.user()
|
|
135
|
+
expect(auth.userId).toBe('user-for-user-call')
|
|
136
|
+
expect(auth.role).toBe(AuthRole.Guest)
|
|
137
|
+
})
|
|
138
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": [
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"@owlmeans/dep-config/tsconfig.base.json",
|
|
4
|
+
"@owlmeans/dep-config/tsconfig.react.json"
|
|
5
5
|
],
|
|
6
6
|
"compilerOptions": {
|
|
7
|
-
"rootDir": "./src/",
|
|
8
|
-
"outDir": "./build/"
|
|
7
|
+
"rootDir": "./src/",
|
|
8
|
+
"outDir": "./build/"
|
|
9
9
|
},
|
|
10
|
-
"exclude": [
|
|
11
|
-
|
|
12
|
-
"./build/**/*",
|
|
13
|
-
"./*.ts"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
10
|
+
"exclude": ["./dist/**/*", "./build/**/*", "./tests/**/*", "./*.ts"]
|
|
11
|
+
}
|