@3sixty/api-auth-service 0.0.0-stage → 0.20.0-next.1
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/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/entities/authenticationAuditEntry.js +121 -0
- package/dist/es/entities/authenticationAuditEntry.js.map +1 -0
- package/dist/es/entities/authenticationRateEntry.js +37 -0
- package/dist/es/entities/authenticationRateEntry.js.map +1 -0
- package/dist/es/index.js +17 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js +4 -0
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js.map +1 -0
- package/dist/es/models/ITenantOverrideProcessorConfig.js +4 -0
- package/dist/es/models/ITenantOverrideProcessorConfig.js.map +1 -0
- package/dist/es/models/ITenantOverrideProcessorConstructorOptions.js +2 -0
- package/dist/es/models/ITenantOverrideProcessorConstructorOptions.js.map +1 -0
- package/dist/es/processors/tenantOverrideProcessor.js +144 -0
- package/dist/es/processors/tenantOverrideProcessor.js.map +1 -0
- package/dist/es/restEntryPoints.js +13 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js +355 -0
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js.map +1 -0
- package/dist/es/schema.js +13 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationAuditService.js +240 -0
- package/dist/es/services/entityStorageAuthenticationAuditService.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationRateService.js +213 -0
- package/dist/es/services/entityStorageAuthenticationRateService.js.map +1 -0
- package/dist/types/entities/authenticationAuditEntry.d.ts +49 -0
- package/dist/types/entities/authenticationRateEntry.d.ts +17 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/models/IEntityStorageAuthenticationAuditServiceConfig.d.ts +9 -0
- package/dist/types/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.d.ts +15 -0
- package/dist/types/models/IEntityStorageAuthenticationRateServiceConfig.d.ts +10 -0
- package/dist/types/models/IEntityStorageAuthenticationRateServiceConstructorOptions.d.ts +25 -0
- package/dist/types/models/ITenantOverrideProcessorConfig.d.ts +19 -0
- package/dist/types/models/ITenantOverrideProcessorConstructorOptions.d.ts +20 -0
- package/dist/types/processors/tenantOverrideProcessor.d.ts +48 -0
- package/dist/types/restEntryPoints.d.ts +5 -0
- package/dist/types/routes/entityStorageAuthenticationAuditRoutes.d.ts +54 -0
- package/dist/types/schema.d.ts +4 -0
- package/dist/types/services/entityStorageAuthenticationAuditService.d.ts +72 -0
- package/dist/types/services/entityStorageAuthenticationRateService.d.ts +60 -0
- package/docs/changelog.md +1633 -0
- package/docs/examples.md +137 -0
- package/docs/open-api/spec.json +911 -0
- package/docs/reference/classes/AuthenticationAuditEntry.md +101 -0
- package/docs/reference/classes/AuthenticationRateEntry.md +37 -0
- package/docs/reference/classes/EntityStorageAuthenticationAuditService.md +241 -0
- package/docs/reference/classes/EntityStorageAuthenticationRateService.md +227 -0
- package/docs/reference/classes/TenantOverrideProcessor.md +129 -0
- package/docs/reference/functions/authenticationAuditCreate.md +37 -0
- package/docs/reference/functions/authenticationAuditGet.md +31 -0
- package/docs/reference/functions/authenticationAuditQuery.md +31 -0
- package/docs/reference/functions/authenticationAuditRemove.md +31 -0
- package/docs/reference/functions/authenticationAuditUpdate.md +31 -0
- package/docs/reference/functions/generateRestRoutesAuthenticationAudit.md +25 -0
- package/docs/reference/functions/initSchema.md +9 -0
- package/docs/reference/index.md +33 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConfig.md +11 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConstructorOptions.md +25 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConfig.md +17 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConstructorOptions.md +53 -0
- package/docs/reference/interfaces/ITenantOverrideProcessorConfig.md +39 -0
- package/docs/reference/interfaces/ITenantOverrideProcessorConstructorOptions.md +39 -0
- package/docs/reference/variables/restEntryPoints.md +5 -0
- package/docs/reference/variables/tagsAuthenticationAudit.md +5 -0
- package/locales/en.json +22 -0
- package/package.json +62 -5
package/docs/examples.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Auth Service Examples
|
|
2
|
+
|
|
3
|
+
These snippets show how to apply rate limiting, record authentication audit entries and allow privileged callers to override the tenant of a request.
|
|
4
|
+
|
|
5
|
+
## EntityStorageAuthenticationRateService
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { EntityStorageAuthenticationRateService } from '@3sixty/api-auth-service';
|
|
9
|
+
import { BaseError, GeneralError } from '@3sixty/core';
|
|
10
|
+
import { TooManyRequestsError } from '@3sixty/api-models';
|
|
11
|
+
|
|
12
|
+
const rateService = new EntityStorageAuthenticationRateService({
|
|
13
|
+
config: {
|
|
14
|
+
cleanupIntervalMinutes: 5
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
console.log(rateService.className()); // EntityStorageAuthenticationRateService
|
|
19
|
+
|
|
20
|
+
await rateService.registerAction('login', {
|
|
21
|
+
maxAttempts: 3,
|
|
22
|
+
windowMinutes: 15
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await rateService.start('default');
|
|
26
|
+
|
|
27
|
+
await rateService.check('login', 'alice@example.org');
|
|
28
|
+
await rateService.check('login', 'alice@example.org');
|
|
29
|
+
await rateService.check('login', 'alice@example.org');
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await rateService.check('login', 'alice@example.org');
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (BaseError.isErrorName(error, TooManyRequestsError.CLASS_NAME)) {
|
|
35
|
+
const tooMany = error as TooManyRequestsError;
|
|
36
|
+
console.log(tooMany.properties?.retryAfterSeconds); // 900
|
|
37
|
+
console.log(tooMany.properties?.nextRequestTime); // 2026-04-13T10:15:00.000Z
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await rateService.clear('login', 'alice@example.org');
|
|
42
|
+
await rateService.unregisterAction('login');
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await rateService.check('login', 'alice@example.org');
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (BaseError.isErrorName(error, GeneralError.CLASS_NAME)) {
|
|
48
|
+
console.log((error as GeneralError).name); // GeneralError
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await rateService.stop('default');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## EntityStorageAuthenticationAuditService
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { EntityStorageAuthenticationAuditService } from '@3sixty/api-auth-service';
|
|
59
|
+
|
|
60
|
+
const auditService = new EntityStorageAuthenticationAuditService({
|
|
61
|
+
config: {
|
|
62
|
+
ipHashSalt: 'StrongServerSideSaltForAuditHashing123'
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log(auditService.className()); // EntityStorageAuthenticationAuditService
|
|
67
|
+
|
|
68
|
+
const createdAuditId = await auditService.create({
|
|
69
|
+
event: 'login-failure',
|
|
70
|
+
actorId: 'did:example:user:alice',
|
|
71
|
+
nodeId: 'did:example:node:eu-west-1',
|
|
72
|
+
organizationId: 'did:example:org:core',
|
|
73
|
+
tenantId: 'did:example:tenant:alpha',
|
|
74
|
+
data: {
|
|
75
|
+
reason: 'invalid-password'
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const auditPage = await auditService.query(
|
|
80
|
+
{
|
|
81
|
+
actorId: 'did:example:user:alice',
|
|
82
|
+
event: 'login-failure',
|
|
83
|
+
startDate: '2026-04-01T00:00:00.000Z',
|
|
84
|
+
endDate: '2026-04-30T23:59:59.999Z'
|
|
85
|
+
},
|
|
86
|
+
undefined,
|
|
87
|
+
50
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
console.log(createdAuditId); // 018f2f67bb9d4a0caad8386f56df85ce
|
|
91
|
+
console.log(auditPage.entries.length); // 1
|
|
92
|
+
console.log(auditPage.cursor); // eyJpZCI6IjAxOGYyZjY3YmI5ZDRhMGNhYWQ4Mzg2ZjU2ZGY4NWNlIn0=
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## TenantOverrideProcessor
|
|
96
|
+
|
|
97
|
+
The processor runs after `AuthHeaderProcessor`. A caller holding the escalated privilege role can supply the `override-tenant` query parameter to act on another tenant.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { TenantOverrideProcessor } from '@3sixty/api-auth-service';
|
|
101
|
+
|
|
102
|
+
const processor = new TenantOverrideProcessor({
|
|
103
|
+
tenantAdminComponentType: 'tenant-admin',
|
|
104
|
+
authorizationComponentType: 'authorization',
|
|
105
|
+
config: {
|
|
106
|
+
escalatedPrivilegeRole: 'global-admin',
|
|
107
|
+
authorizationModelId: 'system'
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
console.log(processor.className()); // TenantOverrideProcessor
|
|
112
|
+
|
|
113
|
+
const request = {
|
|
114
|
+
method: 'get',
|
|
115
|
+
url: '/authentication/audit?override-tenant=did:example:tenant:beta',
|
|
116
|
+
query: {
|
|
117
|
+
'override-tenant': 'did:example:tenant:beta'
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const response = {};
|
|
122
|
+
const contextIds = {
|
|
123
|
+
user: 'did:example:user:admin',
|
|
124
|
+
tenant: 'did:example:tenant:alpha'
|
|
125
|
+
};
|
|
126
|
+
const processorState: { [id: string]: unknown } = {};
|
|
127
|
+
|
|
128
|
+
await processor.pre(
|
|
129
|
+
request,
|
|
130
|
+
response,
|
|
131
|
+
{ operationId: 'auditQuery', path: '/' },
|
|
132
|
+
contextIds,
|
|
133
|
+
processorState
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
console.log(contextIds.tenant); // did:example:tenant:beta
|
|
137
|
+
```
|