@3sixty/api-auth-entity-storage-service 0.0.0-stage → 0.20.0-next.0
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/entities/authenticationUser.js +69 -0
- package/dist/es/entities/authenticationUser.js.map +1 -0
- package/dist/es/index.js +29 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IAuthHeaderProcessorConfig.js +4 -0
- package/dist/es/models/IAuthHeaderProcessorConfig.js.map +1 -0
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js +2 -0
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -0
- package/dist/es/models/IAuthTokenContext.js +4 -0
- package/dist/es/models/IAuthTokenContext.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js +4 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.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/IEntityStorageAuthenticationServiceConfig.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js +2 -0
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -0
- package/dist/es/processors/authHeaderProcessor.js +277 -0
- package/dist/es/processors/authHeaderProcessor.js.map +1 -0
- package/dist/es/restEntryPoints.js +27 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js +367 -0
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js.map +1 -0
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js +343 -0
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js.map +1 -0
- package/dist/es/routes/entityStorageAuthenticationRoutes.js +247 -0
- package/dist/es/routes/entityStorageAuthenticationRoutes.js.map +1 -0
- package/dist/es/schema.js +15 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationAdminService.js +323 -0
- package/dist/es/services/entityStorageAuthenticationAdminService.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/es/services/entityStorageAuthenticationService.js +326 -0
- package/dist/es/services/entityStorageAuthenticationService.js.map +1 -0
- package/dist/es/utils/passwordHelper.js +58 -0
- package/dist/es/utils/passwordHelper.js.map +1 -0
- package/dist/es/utils/tokenHelper.js +142 -0
- package/dist/es/utils/tokenHelper.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/entities/authenticationUser.d.ts +33 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/models/IAuthHeaderProcessorConfig.d.ts +39 -0
- package/dist/types/models/IAuthHeaderProcessorConstructorOptions.d.ts +25 -0
- package/dist/types/models/IAuthTokenContext.d.ts +34 -0
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConfig.d.ts +14 -0
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +20 -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/IEntityStorageAuthenticationServiceConfig.d.ts +36 -0
- package/dist/types/models/IEntityStorageAuthenticationServiceConstructorOptions.d.ts +35 -0
- package/dist/types/processors/authHeaderProcessor.d.ts +57 -0
- package/dist/types/restEntryPoints.d.ts +5 -0
- package/dist/types/routes/entityStorageAuthenticationAdminRoutes.d.ts +62 -0
- package/dist/types/routes/entityStorageAuthenticationAuditRoutes.d.ts +54 -0
- package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +45 -0
- package/dist/types/schema.d.ts +4 -0
- package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +65 -0
- package/dist/types/services/entityStorageAuthenticationAuditService.d.ts +72 -0
- package/dist/types/services/entityStorageAuthenticationRateService.d.ts +60 -0
- package/dist/types/services/entityStorageAuthenticationService.d.ts +65 -0
- package/dist/types/utils/passwordHelper.d.ts +24 -0
- package/dist/types/utils/tokenHelper.d.ts +60 -0
- package/docs/changelog.md +0 -0
- package/docs/examples.md +178 -0
- package/docs/open-api/spec.json +2122 -0
- package/docs/reference/classes/AuthHeaderProcessor.md +193 -0
- package/docs/reference/classes/AuthenticationAuditEntry.md +101 -0
- package/docs/reference/classes/AuthenticationRateEntry.md +37 -0
- package/docs/reference/classes/AuthenticationUser.md +69 -0
- package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +229 -0
- package/docs/reference/classes/EntityStorageAuthenticationAuditService.md +241 -0
- package/docs/reference/classes/EntityStorageAuthenticationRateService.md +227 -0
- package/docs/reference/classes/EntityStorageAuthenticationService.md +221 -0
- package/docs/reference/classes/PasswordHelper.md +74 -0
- package/docs/reference/classes/TokenHelper.md +205 -0
- package/docs/reference/functions/authenticationAdminCreateUser.md +37 -0
- package/docs/reference/functions/authenticationAdminGetUser.md +31 -0
- package/docs/reference/functions/authenticationAdminGetUserByIdentity.md +31 -0
- package/docs/reference/functions/authenticationAdminRemoveUser.md +31 -0
- package/docs/reference/functions/authenticationAdminUpdateUser.md +31 -0
- package/docs/reference/functions/authenticationAdminUpdateUserPassword.md +31 -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/authenticationLogin.md +31 -0
- package/docs/reference/functions/authenticationLogout.md +31 -0
- package/docs/reference/functions/authenticationRefreshToken.md +31 -0
- package/docs/reference/functions/authenticationUpdatePassword.md +31 -0
- package/docs/reference/functions/generateRestRoutesAuthentication.md +25 -0
- package/docs/reference/functions/generateRestRoutesAuthenticationAdmin.md +25 -0
- package/docs/reference/functions/generateRestRoutesAuthenticationAudit.md +25 -0
- package/docs/reference/functions/initSchema.md +9 -0
- package/docs/reference/index.md +57 -0
- package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +86 -0
- package/docs/reference/interfaces/IAuthHeaderProcessorConstructorOptions.md +53 -0
- package/docs/reference/interfaces/IAuthTokenContext.md +60 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +25 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +39 -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/IEntityStorageAuthenticationServiceConfig.md +87 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md +81 -0
- package/docs/reference/variables/restEntryPoints.md +5 -0
- package/docs/reference/variables/tagsAuthentication.md +5 -0
- package/docs/reference/variables/tagsAuthenticationAdmin.md +5 -0
- package/docs/reference/variables/tagsAuthenticationAudit.md +5 -0
- package/locales/en.json +52 -0
- package/package.json +64 -5
package/docs/examples.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Auth Entity Storage Service Examples
|
|
2
|
+
|
|
3
|
+
These snippets show how to wire authentication services into your component container and apply token processing in request pipelines.
|
|
4
|
+
|
|
5
|
+
## EntityStorageAuthenticationAdminService
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { EntityStorageAuthenticationAdminService } from '@3sixty/api-auth-entity-storage-service';
|
|
9
|
+
|
|
10
|
+
const adminService = new EntityStorageAuthenticationAdminService();
|
|
11
|
+
|
|
12
|
+
console.log(adminService.className()); // EntityStorageAuthenticationAdminService
|
|
13
|
+
|
|
14
|
+
await adminService.create({
|
|
15
|
+
email: 'owner@example.org',
|
|
16
|
+
password: 'StartPassword123',
|
|
17
|
+
userIdentity: 'did:example:owner',
|
|
18
|
+
organizationIdentity: 'did:example:org',
|
|
19
|
+
scope: ['admin']
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await adminService.update({
|
|
23
|
+
email: 'owner@example.org',
|
|
24
|
+
scope: ['admin', 'security']
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await adminService.updatePassword('owner@example.org', 'StartPassword124', 'StartPassword123');
|
|
28
|
+
|
|
29
|
+
const fromIdentity = await adminService.getByIdentity('did:example:owner');
|
|
30
|
+
console.log(fromIdentity.scope.length); // 2
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { EntityStorageAuthenticationAdminService } from '@3sixty/api-auth-entity-storage-service';
|
|
35
|
+
|
|
36
|
+
const adminService = new EntityStorageAuthenticationAdminService();
|
|
37
|
+
const user = await adminService.get('owner@example.org');
|
|
38
|
+
await adminService.remove(user.email);
|
|
39
|
+
|
|
40
|
+
console.log(user.email); // owner@example.org
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## EntityStorageAuthenticationService
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { EntityStorageAuthenticationService } from '@3sixty/api-auth-entity-storage-service';
|
|
47
|
+
|
|
48
|
+
const authService = new EntityStorageAuthenticationService();
|
|
49
|
+
|
|
50
|
+
await authService.start('default');
|
|
51
|
+
console.log(authService.className()); // EntityStorageAuthenticationService
|
|
52
|
+
|
|
53
|
+
const loginResult = await authService.login('alice@example.org', 'correct-horse-battery-staple');
|
|
54
|
+
|
|
55
|
+
const refreshResult = await authService.refresh(loginResult.token);
|
|
56
|
+
|
|
57
|
+
await authService.updatePassword('correct-horse-battery-staple', 'correct-horse-battery-staple-2');
|
|
58
|
+
|
|
59
|
+
await authService.logout(refreshResult.token);
|
|
60
|
+
console.log(refreshResult.expiry > 0); // true
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## EntityStorageAuthenticationRateService
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { EntityStorageAuthenticationRateService } from '@3sixty/api-auth-entity-storage-service';
|
|
67
|
+
import { BaseError, GeneralError } from '@3sixty/core';
|
|
68
|
+
import { TooManyRequestsError } from '@3sixty/api-models';
|
|
69
|
+
|
|
70
|
+
const rateService = new EntityStorageAuthenticationRateService({
|
|
71
|
+
config: {
|
|
72
|
+
cleanupIntervalMinutes: 5
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(rateService.className()); // EntityStorageAuthenticationRateService
|
|
77
|
+
|
|
78
|
+
await rateService.registerAction('login', {
|
|
79
|
+
maxAttempts: 3,
|
|
80
|
+
windowMinutes: 15
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await rateService.start('default');
|
|
84
|
+
|
|
85
|
+
await rateService.check('login', 'alice@example.org');
|
|
86
|
+
await rateService.check('login', 'alice@example.org');
|
|
87
|
+
await rateService.check('login', 'alice@example.org');
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await rateService.check('login', 'alice@example.org');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (BaseError.isErrorName(error, TooManyRequestsError.CLASS_NAME)) {
|
|
93
|
+
const tooMany = error as TooManyRequestsError;
|
|
94
|
+
console.log(tooMany.properties?.retryAfterSeconds); // 900
|
|
95
|
+
console.log(tooMany.properties?.nextRequestTime); // 2026-04-13T10:15:00.000Z
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await rateService.clear('login', 'alice@example.org');
|
|
100
|
+
await rateService.unregisterAction('login');
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
await rateService.check('login', 'alice@example.org');
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (BaseError.isErrorName(error, GeneralError.CLASS_NAME)) {
|
|
106
|
+
console.log((error as GeneralError).name); // GeneralError
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await rateService.stop('default');
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## EntityStorageAuthenticationAuditService
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { EntityStorageAuthenticationAuditService } from '@3sixty/api-auth-entity-storage-service';
|
|
117
|
+
|
|
118
|
+
const auditService = new EntityStorageAuthenticationAuditService({
|
|
119
|
+
config: {
|
|
120
|
+
ipHashSalt: 'StrongServerSideSaltForAuditHashing123'
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
console.log(auditService.className()); // EntityStorageAuthenticationAuditService
|
|
125
|
+
|
|
126
|
+
const createdAuditId = await auditService.create({
|
|
127
|
+
event: 'login-failure',
|
|
128
|
+
actorId: 'did:example:user:alice',
|
|
129
|
+
nodeId: 'did:example:node:eu-west-1',
|
|
130
|
+
organizationId: 'did:example:org:core',
|
|
131
|
+
tenantId: 'did:example:tenant:alpha',
|
|
132
|
+
data: {
|
|
133
|
+
reason: 'invalid-password'
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const auditPage = await auditService.query(
|
|
138
|
+
{
|
|
139
|
+
actorId: 'did:example:user:alice',
|
|
140
|
+
event: 'login-failure',
|
|
141
|
+
startDate: '2026-04-01T00:00:00.000Z',
|
|
142
|
+
endDate: '2026-04-30T23:59:59.999Z'
|
|
143
|
+
},
|
|
144
|
+
undefined,
|
|
145
|
+
50
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
console.log(createdAuditId); // 018f2f67bb9d4a0caad8386f56df85ce
|
|
149
|
+
console.log(auditPage.entries.length); // 1
|
|
150
|
+
console.log(auditPage.cursor); // eyJpZCI6IjAxOGYyZjY3YmI5ZDRhMGNhYWQ4Mzg2ZjU2ZGY4NWNlIn0=
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## AuthHeaderProcessor
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { AuthHeaderProcessor } from '@3sixty/api-auth-entity-storage-service';
|
|
157
|
+
|
|
158
|
+
const processor = new AuthHeaderProcessor();
|
|
159
|
+
|
|
160
|
+
await processor.start('default');
|
|
161
|
+
console.log(processor.className()); // AuthHeaderProcessor
|
|
162
|
+
|
|
163
|
+
const request = {
|
|
164
|
+
method: 'get',
|
|
165
|
+
url: '/info',
|
|
166
|
+
headers: {
|
|
167
|
+
authorization: 'Bearer token-value'
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const response = {};
|
|
172
|
+
const contextIds = {};
|
|
173
|
+
const processorState: { [id: string]: unknown } = {};
|
|
174
|
+
|
|
175
|
+
await processor.pre(request, response, { skipAuth: false }, contextIds, processorState);
|
|
176
|
+
|
|
177
|
+
await processor.post(request, response, { skipAuth: false }, contextIds, processorState);
|
|
178
|
+
```
|