@owlmeans/auth 0.1.2 → 0.1.3
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 +44 -284
- package/build/consts.d.ts +2 -1
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +3 -0
- package/build/consts.js.map +1 -1
- package/package.json +7 -4
- package/src/consts.ts +3 -0
- package/tests/consts.spec.ts +35 -0
- package/tests/errors.spec.ts +51 -0
- package/tsconfig.json +5 -9
package/README.md
CHANGED
|
@@ -1,321 +1,81 @@
|
|
|
1
1
|
# @owlmeans/auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core authentication types, schemas, and constants for OwlMeans fullstack applications.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
- **Permission-Based Authorization**: Granular permission and capability management
|
|
12
|
-
- **Profile Management**: User profile and group-based access control
|
|
13
|
-
- **Flexible Authentication Types**: Support for multiple authentication methods including Ed25519, one-time tokens, and wallet-based authentication
|
|
7
|
+
- Defines the shared `Auth`, `AuthCredentials`, `AuthPayload`, and `AuthToken` types used by all auth-related packages
|
|
8
|
+
- Provides AJV schemas for validating auth requests (`AuthCredentialsSchema`, `AllowanceRequestSchema`, etc.)
|
|
9
|
+
- Defines the `AuthRole` and `AuthenticationStage` enums used across server and client
|
|
10
|
+
- Used in request handlers to access `req.auth` and throw typed auth errors
|
|
14
11
|
|
|
15
12
|
## Installation
|
|
16
13
|
|
|
17
14
|
```bash
|
|
18
|
-
|
|
15
|
+
bun add @owlmeans/auth
|
|
19
16
|
```
|
|
20
17
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
### Authentication Types
|
|
24
|
-
|
|
25
|
-
The library supports various authentication methods through the `AuthenticationType` enum:
|
|
26
|
-
|
|
27
|
-
- **BasicEd25519**: Cryptographic authentication using Ed25519 signatures
|
|
28
|
-
- **OneTimeToken**: Temporary token-based authentication
|
|
29
|
-
- **ReCaptcha**: CAPTCHA-based verification
|
|
30
|
-
- **WalletDid**: Decentralized identity wallet authentication
|
|
31
|
-
- **RelyHandshake**: Internal cross-authentication for wallet connections
|
|
32
|
-
- **WalletConsumer**: Client-side wallet authentication
|
|
33
|
-
- **WalletProvider**: Provider-side wallet authentication
|
|
34
|
-
|
|
35
|
-
### Authorization Types
|
|
36
|
-
|
|
37
|
-
Authorization is handled through the `AuthroizationType` enum:
|
|
38
|
-
|
|
39
|
-
- **AuthToken**: Classic bearer token authorization
|
|
40
|
-
- **Ed25519BasicToken**: OwlMeans' primary authorization token
|
|
41
|
-
- **Ed25519BasicSignature**: Signature-based authorization
|
|
42
|
-
|
|
43
|
-
### User Roles
|
|
44
|
-
|
|
45
|
-
The system supports hierarchical roles via the `AuthRole` enum:
|
|
46
|
-
|
|
47
|
-
- **Guest**: Unauthenticated users with limited access
|
|
48
|
-
- **User**: Authenticated regular users
|
|
49
|
-
- **Service**: Service-to-service authentication
|
|
50
|
-
- **Admin**: Administrative users with elevated privileges
|
|
51
|
-
- **Superuser**: Highest privilege level
|
|
52
|
-
- **System**: System-level processes
|
|
53
|
-
- **Blocked**: Restricted/banned users
|
|
54
|
-
|
|
55
|
-
## API Reference
|
|
18
|
+
## Usage
|
|
56
19
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
#### `AuthCredentials`
|
|
60
|
-
Contains authentication challenge and credential information.
|
|
20
|
+
Throw a typed auth error when a request lacks an entity:
|
|
61
21
|
|
|
62
22
|
```typescript
|
|
63
|
-
|
|
64
|
-
challenge: string
|
|
65
|
-
credential: string
|
|
66
|
-
publicKey?: string
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
#### `AuthPayload`
|
|
71
|
-
Core authentication payload with user and authorization data.
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
interface AuthPayload extends ProfilePayload {
|
|
75
|
-
type: string
|
|
76
|
-
role: AuthRole
|
|
77
|
-
userId: string
|
|
78
|
-
source?: string
|
|
79
|
-
profileId?: string
|
|
80
|
-
expiresAt?: Date
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
#### `Auth`
|
|
85
|
-
Complete authentication object with token and metadata.
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
interface Auth extends AuthPayload {
|
|
89
|
-
token: string
|
|
90
|
-
isUser: boolean
|
|
91
|
-
createdAt: Date
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### `Profile`
|
|
96
|
-
User profile with permissions and group membership.
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
interface Profile extends ProfilePayload {
|
|
100
|
-
id: string
|
|
101
|
-
name: string
|
|
102
|
-
credential?: string
|
|
103
|
-
secret?: string
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
#### `Authorization`
|
|
108
|
-
Permission and capability structure for access control.
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
interface Authorization {
|
|
112
|
-
entityId?: string
|
|
113
|
-
scopes: string[]
|
|
114
|
-
permissions?: PermissionSet[]
|
|
115
|
-
attributes?: AttributeSet[]
|
|
116
|
-
permissioned?: boolean
|
|
117
|
-
denormalized?: boolean
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
#### `PermissionSet`
|
|
122
|
-
Defines capabilities within a specific scope.
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
interface PermissionSet {
|
|
126
|
-
scope: string
|
|
127
|
-
title?: string
|
|
128
|
-
permissions: Capabilties
|
|
129
|
-
resources?: string[]
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Helper Functions
|
|
134
|
-
|
|
135
|
-
#### `verifyAuth(auth: Auth): boolean`
|
|
136
|
-
Validates an authentication object against the defined schema.
|
|
137
|
-
|
|
138
|
-
#### `verifyAuthCredentials(auth: AuthCredentials): boolean`
|
|
139
|
-
Validates authentication credentials against the defined schema.
|
|
23
|
+
import { AuthUnknown } from '@owlmeans/auth'
|
|
140
24
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
#### `isAuthToken(auth: unknown): auth is AuthToken`
|
|
148
|
-
Type guard to check if an object is a valid AuthToken.
|
|
149
|
-
|
|
150
|
-
### Constants
|
|
151
|
-
|
|
152
|
-
#### Authentication Scopes
|
|
153
|
-
- `ALL_SCOPES`: Wildcard scope (`'*'`)
|
|
154
|
-
- `AUTH_SCOPE`: Authentication-specific scope (`'__auth'`)
|
|
155
|
-
|
|
156
|
-
#### Authentication Stages
|
|
157
|
-
```typescript
|
|
158
|
-
enum AuthenticationStage {
|
|
159
|
-
Error = 'error',
|
|
160
|
-
Init = 'init',
|
|
161
|
-
Allowence = 'allowence',
|
|
162
|
-
Authenticate = 'authenticate',
|
|
163
|
-
Authentication = 'auhtentication',
|
|
164
|
-
Authenticated = 'authenticated'
|
|
165
|
-
}
|
|
25
|
+
export const create = handleBody(async (body, context, request) => {
|
|
26
|
+
if (request.auth?.entityId == null) {
|
|
27
|
+
throw new AuthUnknown('entity')
|
|
28
|
+
}
|
|
29
|
+
// ...
|
|
30
|
+
})
|
|
166
31
|
```
|
|
167
32
|
|
|
168
|
-
|
|
169
|
-
- `AUTHEN`: Authentication module base
|
|
170
|
-
- `AUTHEN_INIT`: Authentication initialization
|
|
171
|
-
- `AUTHEN_AUTHEN`: Authentication execution
|
|
172
|
-
- `CAUTHEN`: Client authentication module base
|
|
173
|
-
|
|
174
|
-
### Error Types
|
|
175
|
-
|
|
176
|
-
The package provides a comprehensive error hierarchy for authentication failures:
|
|
177
|
-
|
|
178
|
-
#### `AuthError`
|
|
179
|
-
Base error class for all authentication-related errors.
|
|
180
|
-
|
|
181
|
-
#### `AuthUnknown`
|
|
182
|
-
Error for unknown authentication issues.
|
|
183
|
-
|
|
184
|
-
#### `AuthManagerError`
|
|
185
|
-
Errors related to authentication manager operations.
|
|
186
|
-
|
|
187
|
-
#### `AuthManagerUnsupported`
|
|
188
|
-
Error for unsupported authentication methods.
|
|
189
|
-
|
|
190
|
-
#### `AuthenFailed`
|
|
191
|
-
General authentication failure error.
|
|
192
|
-
|
|
193
|
-
#### `AuthenExists`
|
|
194
|
-
Error when attempting to create duplicate authentication.
|
|
195
|
-
|
|
196
|
-
#### `AuthenPayloadError`
|
|
197
|
-
Error for invalid authentication payload.
|
|
198
|
-
|
|
199
|
-
#### `AuthPluginError`
|
|
200
|
-
Errors related to authentication plugins.
|
|
201
|
-
|
|
202
|
-
#### `TypeMissmatchError`
|
|
203
|
-
Error for authentication type mismatches.
|
|
204
|
-
|
|
205
|
-
#### `AuthorizationError`
|
|
206
|
-
Base error for authorization failures.
|
|
207
|
-
|
|
208
|
-
#### `AuthForbidden`
|
|
209
|
-
Error for forbidden access attempts.
|
|
210
|
-
|
|
211
|
-
#### `ProfileError`
|
|
212
|
-
Errors related to user profile operations.
|
|
213
|
-
|
|
214
|
-
#### `ProfileConsistencyError`
|
|
215
|
-
Error for profile data consistency issues.
|
|
216
|
-
|
|
217
|
-
## Usage Examples
|
|
218
|
-
|
|
219
|
-
### Basic Authentication Validation
|
|
33
|
+
Check authentication stage in a WebSocket connection:
|
|
220
34
|
|
|
221
35
|
```typescript
|
|
222
|
-
import {
|
|
223
|
-
|
|
224
|
-
// Validate an authentication object
|
|
225
|
-
const auth = {
|
|
226
|
-
type: 'basic-ed25519',
|
|
227
|
-
role: AuthRole.User,
|
|
228
|
-
userId: 'user123',
|
|
229
|
-
token: 'token123',
|
|
230
|
-
isUser: true,
|
|
231
|
-
createdAt: new Date(),
|
|
232
|
-
scopes: ['read', 'write']
|
|
233
|
-
}
|
|
36
|
+
import { AuthenticationStage } from '@owlmeans/auth'
|
|
234
37
|
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Type checking
|
|
240
|
-
if (isAuth(someObject)) {
|
|
241
|
-
// TypeScript knows someObject is Auth
|
|
242
|
-
console.log(`User ID: ${someObject.userId}`)
|
|
38
|
+
if (connection.stage !== AuthenticationStage.Authenticated) {
|
|
39
|
+
throw new AuthUnknown('not-authenticated')
|
|
243
40
|
}
|
|
244
41
|
```
|
|
245
42
|
|
|
246
|
-
|
|
43
|
+
## API
|
|
247
44
|
|
|
248
|
-
|
|
249
|
-
import { PermissionSet, AuthRole } from '@owlmeans/auth'
|
|
45
|
+
### Types
|
|
250
46
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
read: true,
|
|
256
|
-
write: true,
|
|
257
|
-
delete: false
|
|
258
|
-
},
|
|
259
|
-
resources: ['doc1', 'doc2']
|
|
260
|
-
}
|
|
261
|
-
```
|
|
47
|
+
- `Auth` — the auth object attached to `request.auth`; contains `userId`, `entityId`, `role`, `scopes`
|
|
48
|
+
- `AuthCredentials` — signed credential payload with `challenge`, `credential`, `publicKey`
|
|
49
|
+
- `AuthPayload` — base payload with `type`, `role`, `userId`, `profileId`, `expiresAt`
|
|
50
|
+
- `AuthToken` — JWT-like token structure
|
|
262
51
|
|
|
263
|
-
###
|
|
52
|
+
### Enums
|
|
264
53
|
|
|
265
54
|
```typescript
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// Authentication operation
|
|
270
|
-
} catch (error) {
|
|
271
|
-
if (error instanceof AuthForbidden) {
|
|
272
|
-
console.log('Access denied')
|
|
273
|
-
} else if (error instanceof AuthError) {
|
|
274
|
-
console.log('Authentication error:', error.message)
|
|
275
|
-
}
|
|
276
|
-
}
|
|
55
|
+
enum AuthRole { User, Guest, Service, System, Admin, Superuser, Blocked }
|
|
56
|
+
enum AuthenticationType { BasicEd25519, OneTimeToken, ReCaptcha }
|
|
57
|
+
enum AuthenticationStage { /* connection auth lifecycle */ }
|
|
277
58
|
```
|
|
278
59
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
The `@owlmeans/auth` package integrates seamlessly with other OwlMeans packages:
|
|
282
|
-
|
|
283
|
-
- **@owlmeans/basic-keys**: Provides cryptographic key management for signature-based authentication
|
|
284
|
-
- **@owlmeans/error**: Uses the ResilientError system for type-safe error handling
|
|
285
|
-
- **@owlmeans/context**: Integrates with the dependency injection system for service registration
|
|
286
|
-
- **@owlmeans/server-auth**: Server-side authentication implementation
|
|
287
|
-
- **@owlmeans/client-auth**: Client-side authentication implementation
|
|
288
|
-
|
|
289
|
-
## Package Structure
|
|
290
|
-
|
|
291
|
-
The authentication system is organized into several specialized modules:
|
|
292
|
-
|
|
293
|
-
- **allowance/**: Authentication request and response handling
|
|
294
|
-
- **auth/**: Core authentication logic and models
|
|
295
|
-
- **permission/**: Permission and capability management
|
|
296
|
-
- **rely/**: Wallet and third-party authentication rely functionality
|
|
297
|
-
- **entity/**: Entity-based authentication and authorization
|
|
298
|
-
|
|
299
|
-
## Advanced Features
|
|
60
|
+
### Errors
|
|
300
61
|
|
|
301
|
-
|
|
302
|
-
The system supports hierarchical permission scopes with wildcard and specific resource targeting.
|
|
62
|
+
- `AuthUnknown` — thrown when a request is missing or has invalid auth
|
|
303
63
|
|
|
304
|
-
|
|
305
|
-
Support for entity-specific permissions and cross-entity authorization.
|
|
64
|
+
## Product-Viable Integration Notes
|
|
306
65
|
|
|
307
|
-
|
|
308
|
-
|
|
66
|
+
- Manager API handlers use `AuthUnknown('entity')` when `request.auth?.entityId` is missing.
|
|
67
|
+
- WebSocket helpers use `Auth`, `AuthToken`, and `AuthenticationStage` to authenticate token-bearing connections.
|
|
68
|
+
- Google/OIDC login is normalized into an `AuthPayload` with `userId`, `profileId`, `entityId`, and `scopes`; the local identity store lives in `@owlmeans/server-auth-identity`.
|
|
69
|
+
- Gate denial should use `AuthForbidden`; product ownership checks should stay in module gates or handlers, not in this core package.
|
|
309
70
|
|
|
310
|
-
###
|
|
311
|
-
Built-in support for decentralized identity wallets and blockchain-based authentication.
|
|
71
|
+
### AJV Schemas (for module filter definitions)
|
|
312
72
|
|
|
313
|
-
|
|
73
|
+
- `AuthCredentialsSchema` — validates an auth credential request body
|
|
74
|
+
- `AllowanceRequestSchema` — validates an allowance/init request body
|
|
75
|
+
- `AuthTokenSchema` — validates query params containing an auth token
|
|
314
76
|
|
|
315
|
-
|
|
316
|
-
- Store credentials securely using appropriate encryption
|
|
317
|
-
- Implement proper session management and token expiration
|
|
318
|
-
- Use signature-based authentication for high-security requirements
|
|
319
|
-
- Validate all authentication payloads using the provided validation functions
|
|
77
|
+
## Related Packages
|
|
320
78
|
|
|
321
|
-
|
|
79
|
+
- [`@owlmeans/auth-common`](../auth-common) — auth modules, guards, and middleware
|
|
80
|
+
- [`@owlmeans/server-auth`](../server-auth) — server-side auth service implementation
|
|
81
|
+
- [`@owlmeans/client-auth`](../client-auth) — client-side auth service
|
package/build/consts.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export declare enum AuthenticationType {
|
|
|
21
21
|
WalletDid = "wallet-did",
|
|
22
22
|
RelyHandshake = "rely-handshake",
|
|
23
23
|
WalletConsumer = "wallet-consumer",
|
|
24
|
-
WalletProvider = "wallet-provider"
|
|
24
|
+
WalletProvider = "wallet-provider",
|
|
25
|
+
Google = "google-oauth"
|
|
25
26
|
}
|
|
26
27
|
export declare enum AuthroizationType {
|
|
27
28
|
AuthToken = "auth-token",
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEzC,eAAO,MAAM,OAAO,MAAM,CAAA;AAC1B,eAAO,MAAM,OAAO,MAAM,CAAA;AAC1B,eAAO,MAAM,QAAQ,MAAM,CAAA;AAC3B,eAAO,MAAM,SAAS,MAAM,CAAA;AAE5B,eAAO,MAAM,UAAU,MAAM,CAAA;AAC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C,eAAO,MAAM,UAAU,UAAU,CAAA;AACjC,eAAO,MAAM,YAAY,WAAW,CAAA;AACpC,eAAO,MAAM,aAAa,YAAY,CAAA;AAEtC,eAAO,MAAM,aAAa,yBAAyB,CAAA;AACnD,eAAO,MAAM,cAAc,QAAsC,CAAA;AAEjE,eAAO,MAAM,QAAQ,YAAY,CAAA;AACjC,eAAO,MAAM,QAAQ,SAAS,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -46,6 +46,9 @@ export var AuthenticationType;
|
|
|
46
46
|
// For OwlMeans Auth Manager Service (OwlMeans IAM) there is a propritary protocol
|
|
47
47
|
// that is used as provider type
|
|
48
48
|
AuthenticationType["WalletProvider"] = "wallet-provider";
|
|
49
|
+
// Google OAuth 2.0 authentication type - used for direct Google sign-in
|
|
50
|
+
// without a full OIDC relay party service in between.
|
|
51
|
+
AuthenticationType["Google"] = "google-oauth";
|
|
49
52
|
})(AuthenticationType || (AuthenticationType = {}));
|
|
50
53
|
export var AuthroizationType;
|
|
51
54
|
(function (AuthroizationType) {
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAA;AAC1B,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAA;AAC1B,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAA;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA;AAElC,MAAM,CAAN,IAAY,QAQX;AARD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,2BAAe,CAAA;IACf,mCAAuB,CAAA;IACvB,+BAA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B,GAAG,GAAG,UAAU,iBAAiB,CAAA;AAE/D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,MAAM,OAAO,CAAA;AAE3C,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAA;AAC1C,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAA;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAA;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAA;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAA;AACnD,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AAEjE,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAA;AACjC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc -b",
|
|
8
8
|
"dev": "sleep 24 && 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",
|
|
@@ -21,16 +22,18 @@
|
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@owlmeans/error": "^0.1.
|
|
25
|
+
"@owlmeans/error": "^0.1.3",
|
|
25
26
|
"ajv-formats": "^3.0.1"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"ajv": "*"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@owlmeans/dep-config": "workspace:*",
|
|
33
|
+
"@types/bun": "^1.3.0",
|
|
31
34
|
"nodemon": "^3.1.11",
|
|
32
35
|
"npm-check": "^6.0.1",
|
|
33
|
-
"typescript": "^
|
|
36
|
+
"typescript": "^6.0.2"
|
|
34
37
|
},
|
|
35
38
|
"publishConfig": {
|
|
36
39
|
"access": "public"
|
package/src/consts.ts
CHANGED
|
@@ -49,6 +49,9 @@ export enum AuthenticationType {
|
|
|
49
49
|
// For OwlMeans Auth Manager Service (OwlMeans IAM) there is a propritary protocol
|
|
50
50
|
// that is used as provider type
|
|
51
51
|
WalletProvider = 'wallet-provider',
|
|
52
|
+
// Google OAuth 2.0 authentication type - used for direct Google sign-in
|
|
53
|
+
// without a full OIDC relay party service in between.
|
|
54
|
+
Google = 'google-oauth',
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
export enum AuthroizationType {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
AUTH_HEADER,
|
|
4
|
+
AuthRole,
|
|
5
|
+
AuthenticationType,
|
|
6
|
+
AuthroizationType,
|
|
7
|
+
} from '@owlmeans/auth'
|
|
8
|
+
|
|
9
|
+
describe('@owlmeans/auth — protocol constants', () => {
|
|
10
|
+
// Both viable and viable-agent rely on these string values being stable —
|
|
11
|
+
// they end up in HTTP headers (`Authorization: ED25519-BASIC-TOKEN ...`)
|
|
12
|
+
// and trusted-record `role` fields (e.g. AuthRole.Service).
|
|
13
|
+
test('AUTH_HEADER is the lowercase HTTP header name', () => {
|
|
14
|
+
expect(AUTH_HEADER).toBe('authorization')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('AuthRole exposes the canonical roles consumers reference', () => {
|
|
18
|
+
expect(AuthRole.User).toBe('user')
|
|
19
|
+
expect(AuthRole.Service).toBe('service')
|
|
20
|
+
expect(AuthRole.Superuser).toBe('superuser')
|
|
21
|
+
expect(AuthRole.Guest).toBe('guest')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('AuthroizationType.Ed25519BasicToken matches the bearer prefix used by basic-ed25519 guard', () => {
|
|
25
|
+
expect(AuthroizationType.Ed25519BasicToken).toBe('ed25519-basic-token')
|
|
26
|
+
expect(AuthroizationType.Ed25519BasicSignature).toBe('ed25519-basic-signature')
|
|
27
|
+
// The header value from auth-common's basic-ed25519 guard upper-cases this prefix.
|
|
28
|
+
expect(AuthroizationType.Ed25519BasicToken.toUpperCase()).toBe('ED25519-BASIC-TOKEN')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('AuthenticationType covers the protocol paths viable consumers use', () => {
|
|
32
|
+
expect(AuthenticationType.BasicEd25519).toBe('basic-ed25519')
|
|
33
|
+
expect(AuthenticationType.OneTimeToken).toBe('one-time-token')
|
|
34
|
+
})
|
|
35
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
AuthError,
|
|
4
|
+
AuthForbidden,
|
|
5
|
+
AuthorizationError,
|
|
6
|
+
AuthenFailed,
|
|
7
|
+
AuthenPayloadError,
|
|
8
|
+
} from '@owlmeans/auth'
|
|
9
|
+
|
|
10
|
+
describe('@owlmeans/auth — error inheritance chain', () => {
|
|
11
|
+
// Matches viable-agent/packages/template/packages/backend/src/utils/auth-guard.ts
|
|
12
|
+
// which throws `new AuthForbidden('token')` and relies on broad `AuthError` catches
|
|
13
|
+
// upstream in the request lifecycle.
|
|
14
|
+
test('AuthForbidden is a kind of AuthorizationError, AuthError, and Error', () => {
|
|
15
|
+
const err = new AuthForbidden('token')
|
|
16
|
+
expect(err).toBeInstanceOf(AuthForbidden)
|
|
17
|
+
expect(err).toBeInstanceOf(AuthorizationError)
|
|
18
|
+
expect(err).toBeInstanceOf(AuthError)
|
|
19
|
+
expect(err).toBeInstanceOf(Error)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('AuthenPayloadError is a kind of AuthenFailed and AuthError', () => {
|
|
23
|
+
const err = new AuthenPayloadError('schema-mismatch')
|
|
24
|
+
expect(err).toBeInstanceOf(AuthenPayloadError)
|
|
25
|
+
expect(err).toBeInstanceOf(AuthenFailed)
|
|
26
|
+
expect(err).toBeInstanceOf(AuthError)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('subclass instances expose the leaf typeName via `type`', () => {
|
|
30
|
+
const forbidden = new AuthForbidden('token')
|
|
31
|
+
const failed = new AuthenFailed('signature')
|
|
32
|
+
expect(forbidden.type).toBe(AuthForbidden.typeName)
|
|
33
|
+
expect(failed.type).toBe(AuthenFailed.typeName)
|
|
34
|
+
expect(forbidden.type).not.toBe(failed.type)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('a try/catch on AuthError catches every auth-package subclass', () => {
|
|
38
|
+
const thrown: AuthError[] = []
|
|
39
|
+
for (const make of [
|
|
40
|
+
() => new AuthForbidden('a'),
|
|
41
|
+
() => new AuthenFailed('b'),
|
|
42
|
+
() => new AuthenPayloadError('c'),
|
|
43
|
+
]) {
|
|
44
|
+
try { throw make() } catch (e) {
|
|
45
|
+
if (!(e instanceof AuthError)) throw e
|
|
46
|
+
thrown.push(e)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
expect(thrown).toHaveLength(3)
|
|
50
|
+
})
|
|
51
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +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/"
|
|
6
|
+
"rootDir": "./src/",
|
|
7
|
+
"outDir": "./build/"
|
|
8
8
|
},
|
|
9
|
-
"exclude": [
|
|
10
|
-
|
|
11
|
-
"./build/**/*",
|
|
12
|
-
"./*.ts"
|
|
13
|
-
]
|
|
14
|
-
}
|
|
9
|
+
"exclude": ["./dist/**/*", "./build/**/*", "./tests/**/*", "./*.ts"]
|
|
10
|
+
}
|