@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
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { HttpContextIdKeys, HttpHeaderHelper, HttpUrlHelper } from "@3sixty/api-models";
|
|
2
|
+
import { ContextIdStore } from "@3sixty/context";
|
|
3
|
+
import { Coerce, ComponentFactory, Guards } from "@3sixty/core";
|
|
4
|
+
import { HeaderTypes, HttpStatusCode } from "@3sixty/web";
|
|
5
|
+
/**
|
|
6
|
+
* The source used when communicating about these routes.
|
|
7
|
+
*/
|
|
8
|
+
const ROUTES_SOURCE = "authenticationAuditRoutes";
|
|
9
|
+
/**
|
|
10
|
+
* The tag to associate with the routes.
|
|
11
|
+
*/
|
|
12
|
+
export const tagsAuthenticationAudit = [
|
|
13
|
+
{
|
|
14
|
+
name: "Authentication Audit",
|
|
15
|
+
description: "Authentication audit endpoints for the REST server."
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* The REST routes for authentication audit.
|
|
20
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
21
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
22
|
+
* @returns The generated routes.
|
|
23
|
+
*/
|
|
24
|
+
export function generateRestRoutesAuthenticationAudit(baseRouteName, componentName) {
|
|
25
|
+
const createRoute = {
|
|
26
|
+
operationId: "authenticationAuditCreate",
|
|
27
|
+
summary: "Create an authentication audit entry",
|
|
28
|
+
tag: tagsAuthenticationAudit[0].name,
|
|
29
|
+
method: "POST",
|
|
30
|
+
path: `${baseRouteName}`,
|
|
31
|
+
handler: async (httpRequestContext, request) => authenticationAuditCreate(httpRequestContext, componentName, request, baseRouteName),
|
|
32
|
+
requestType: {
|
|
33
|
+
type: "IAuditCreateRequest",
|
|
34
|
+
examples: [
|
|
35
|
+
{
|
|
36
|
+
id: "authenticationAuditCreateRequestExample",
|
|
37
|
+
description: "The request to create an authentication audit entry.",
|
|
38
|
+
request: {
|
|
39
|
+
body: {
|
|
40
|
+
actorId: "user@example.com",
|
|
41
|
+
event: "login-success",
|
|
42
|
+
data: {
|
|
43
|
+
organizationIdentity: "did:example:org1"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
responseType: [
|
|
51
|
+
{
|
|
52
|
+
type: "ICreatedResponse",
|
|
53
|
+
examples: [
|
|
54
|
+
{
|
|
55
|
+
id: "authenticationAuditCreateResponseExample",
|
|
56
|
+
description: "The response for creating an authentication audit entry.",
|
|
57
|
+
response: {
|
|
58
|
+
statusCode: 201,
|
|
59
|
+
headers: {
|
|
60
|
+
[HeaderTypes.Location]: "018f0b53d5d5704fa3a06d6ed2478575"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: "IUnauthorizedResponse"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
requiredScope: ["user-admin"]
|
|
71
|
+
};
|
|
72
|
+
const getRoute = {
|
|
73
|
+
operationId: "authenticationAuditGet",
|
|
74
|
+
summary: "Get an authentication audit entry",
|
|
75
|
+
tag: tagsAuthenticationAudit[0].name,
|
|
76
|
+
method: "GET",
|
|
77
|
+
path: `${baseRouteName}/:id`,
|
|
78
|
+
handler: async (httpRequestContext, request) => authenticationAuditGet(httpRequestContext, componentName, request),
|
|
79
|
+
requestType: {
|
|
80
|
+
type: "IAuditGetRequest",
|
|
81
|
+
examples: [
|
|
82
|
+
{
|
|
83
|
+
id: "authenticationAuditGetRequestExample",
|
|
84
|
+
description: "The request to get an authentication audit entry.",
|
|
85
|
+
request: {
|
|
86
|
+
pathParams: {
|
|
87
|
+
id: "018f0b53d5d5704fa3a06d6ed2478575"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
responseType: [
|
|
94
|
+
{
|
|
95
|
+
type: "IAuditGetResponse",
|
|
96
|
+
examples: [
|
|
97
|
+
{
|
|
98
|
+
id: "authenticationAuditGetResponseExample",
|
|
99
|
+
description: "The response for getting an authentication audit entry.",
|
|
100
|
+
response: {
|
|
101
|
+
body: {
|
|
102
|
+
id: "018f0b53d5d5704fa3a06d6ed2478575",
|
|
103
|
+
actorId: "user@example.com",
|
|
104
|
+
dateCreated: "2026-01-12T09:05:23.123Z",
|
|
105
|
+
event: "login-success",
|
|
106
|
+
data: {
|
|
107
|
+
organizationIdentity: "did:example:org1"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: "IUnauthorizedResponse"
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
requiredScope: ["user-admin"]
|
|
119
|
+
};
|
|
120
|
+
const updateRoute = {
|
|
121
|
+
operationId: "authenticationAuditUpdate",
|
|
122
|
+
summary: "Update an authentication audit entry",
|
|
123
|
+
tag: tagsAuthenticationAudit[0].name,
|
|
124
|
+
method: "PUT",
|
|
125
|
+
path: `${baseRouteName}/:id`,
|
|
126
|
+
handler: async (httpRequestContext, request) => authenticationAuditUpdate(httpRequestContext, componentName, request),
|
|
127
|
+
requestType: {
|
|
128
|
+
type: "IAuditUpdateRequest",
|
|
129
|
+
examples: [
|
|
130
|
+
{
|
|
131
|
+
id: "authenticationAuditUpdateRequestExample",
|
|
132
|
+
description: "The request to update an authentication audit entry.",
|
|
133
|
+
request: {
|
|
134
|
+
pathParams: {
|
|
135
|
+
id: "018f0b53d5d5704fa3a06d6ed2478575"
|
|
136
|
+
},
|
|
137
|
+
body: {
|
|
138
|
+
data: {
|
|
139
|
+
organizationIdentity: "did:example:org1"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
responseType: [
|
|
147
|
+
{
|
|
148
|
+
type: "INoContentResponse"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: "IUnauthorizedResponse"
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
requiredScope: ["user-admin"]
|
|
155
|
+
};
|
|
156
|
+
const removeRoute = {
|
|
157
|
+
operationId: "authenticationAuditRemove",
|
|
158
|
+
summary: "Remove an authentication audit entry",
|
|
159
|
+
tag: tagsAuthenticationAudit[0].name,
|
|
160
|
+
method: "DELETE",
|
|
161
|
+
path: `${baseRouteName}/:id`,
|
|
162
|
+
handler: async (httpRequestContext, request) => authenticationAuditRemove(httpRequestContext, componentName, request),
|
|
163
|
+
requestType: {
|
|
164
|
+
type: "IAuditRemoveRequest",
|
|
165
|
+
examples: [
|
|
166
|
+
{
|
|
167
|
+
id: "authenticationAuditRemoveRequestExample",
|
|
168
|
+
description: "The request to remove an authentication audit entry.",
|
|
169
|
+
request: {
|
|
170
|
+
pathParams: {
|
|
171
|
+
id: "018f0b53d5d5704fa3a06d6ed2478575"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
responseType: [
|
|
178
|
+
{
|
|
179
|
+
type: "INoContentResponse"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: "IUnauthorizedResponse"
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
requiredScope: ["user-admin"]
|
|
186
|
+
};
|
|
187
|
+
const queryRoute = {
|
|
188
|
+
operationId: "authenticationAuditQuery",
|
|
189
|
+
summary: "Query authentication audit entries",
|
|
190
|
+
tag: tagsAuthenticationAudit[0].name,
|
|
191
|
+
method: "GET",
|
|
192
|
+
path: `${baseRouteName}`,
|
|
193
|
+
handler: async (httpRequestContext, request) => authenticationAuditQuery(httpRequestContext, componentName, request),
|
|
194
|
+
requestType: {
|
|
195
|
+
type: "IAuditQueryRequest",
|
|
196
|
+
examples: [
|
|
197
|
+
{
|
|
198
|
+
id: "authenticationAuditQueryRequestExample",
|
|
199
|
+
description: "The request to query authentication audit entries.",
|
|
200
|
+
request: {
|
|
201
|
+
query: {
|
|
202
|
+
actorId: "user@example.com",
|
|
203
|
+
event: "login-success",
|
|
204
|
+
startDate: "2026-01-01T00:00:00.000Z",
|
|
205
|
+
endDate: "2026-01-31T23:59:59.999Z",
|
|
206
|
+
limit: "50"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
responseType: [
|
|
213
|
+
{
|
|
214
|
+
type: "IAuditQueryResponse",
|
|
215
|
+
examples: [
|
|
216
|
+
{
|
|
217
|
+
id: "authenticationAuditQueryResponseExample",
|
|
218
|
+
description: "The response for querying authentication audit entries.",
|
|
219
|
+
response: {
|
|
220
|
+
body: {
|
|
221
|
+
entries: [
|
|
222
|
+
{
|
|
223
|
+
id: "018f0b53d5d5704fa3a06d6ed2478575",
|
|
224
|
+
actorId: "user@example.com",
|
|
225
|
+
dateCreated: "2026-01-12T09:05:23.123Z",
|
|
226
|
+
event: "login-success",
|
|
227
|
+
data: {
|
|
228
|
+
organizationIdentity: "did:example:org1"
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
cursor: "next-cursor"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: "IUnauthorizedResponse"
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
requiredScope: ["user-admin"]
|
|
243
|
+
};
|
|
244
|
+
return [createRoute, getRoute, updateRoute, removeRoute, queryRoute];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create an authentication audit entry.
|
|
248
|
+
* @param httpRequestContext The request context for the API.
|
|
249
|
+
* @param componentName The name of the component to use in the routes.
|
|
250
|
+
* @param request The request.
|
|
251
|
+
* @param baseRouteName The base route name to use for the location header.
|
|
252
|
+
* @returns The response object with additional http response properties.
|
|
253
|
+
*/
|
|
254
|
+
export async function authenticationAuditCreate(httpRequestContext, componentName, request, baseRouteName) {
|
|
255
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
256
|
+
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
257
|
+
const component = ComponentFactory.get(componentName);
|
|
258
|
+
const id = await component.create(request.body);
|
|
259
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
260
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
261
|
+
const headers = {};
|
|
262
|
+
HttpHeaderHelper.buildId(headers, id, HttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`));
|
|
263
|
+
return {
|
|
264
|
+
statusCode: HttpStatusCode.created,
|
|
265
|
+
headers
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get an authentication audit entry.
|
|
270
|
+
* @param httpRequestContext The request context for the API.
|
|
271
|
+
* @param componentName The name of the component to use in the routes.
|
|
272
|
+
* @param request The request.
|
|
273
|
+
* @returns The response object with additional http response properties.
|
|
274
|
+
*/
|
|
275
|
+
export async function authenticationAuditGet(httpRequestContext, componentName, request) {
|
|
276
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
277
|
+
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
278
|
+
const component = ComponentFactory.get(componentName);
|
|
279
|
+
const entry = await component.get(request.pathParams.id);
|
|
280
|
+
return {
|
|
281
|
+
body: entry
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Update an authentication audit entry.
|
|
286
|
+
* @param httpRequestContext The request context for the API.
|
|
287
|
+
* @param componentName The name of the component to use in the routes.
|
|
288
|
+
* @param request The request.
|
|
289
|
+
* @returns The response object with additional http response properties.
|
|
290
|
+
*/
|
|
291
|
+
export async function authenticationAuditUpdate(httpRequestContext, componentName, request) {
|
|
292
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
293
|
+
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
294
|
+
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
295
|
+
const component = ComponentFactory.get(componentName);
|
|
296
|
+
await component.update(request.pathParams.id, request.body);
|
|
297
|
+
return {
|
|
298
|
+
statusCode: HttpStatusCode.noContent
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Remove an authentication audit entry.
|
|
303
|
+
* @param httpRequestContext The request context for the API.
|
|
304
|
+
* @param componentName The name of the component to use in the routes.
|
|
305
|
+
* @param request The request.
|
|
306
|
+
* @returns The response object with additional http response properties.
|
|
307
|
+
*/
|
|
308
|
+
export async function authenticationAuditRemove(httpRequestContext, componentName, request) {
|
|
309
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
310
|
+
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
311
|
+
const component = ComponentFactory.get(componentName);
|
|
312
|
+
await component.remove(request.pathParams.id);
|
|
313
|
+
return {
|
|
314
|
+
statusCode: HttpStatusCode.noContent
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Query authentication audit entries.
|
|
319
|
+
* @param httpRequestContext The request context for the API.
|
|
320
|
+
* @param componentName The name of the component to use in the routes.
|
|
321
|
+
* @param request The request.
|
|
322
|
+
* @returns The response object with additional http response properties.
|
|
323
|
+
*/
|
|
324
|
+
export async function authenticationAuditQuery(httpRequestContext, componentName, request) {
|
|
325
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
326
|
+
const component = ComponentFactory.get(componentName);
|
|
327
|
+
const result = await component.query({
|
|
328
|
+
actorId: request.query?.actorId,
|
|
329
|
+
organizationId: request.query?.organizationId,
|
|
330
|
+
tenantId: request.query?.tenantId,
|
|
331
|
+
nodeId: request.query?.nodeId,
|
|
332
|
+
event: request.query?.event,
|
|
333
|
+
startDate: request.query?.startDate,
|
|
334
|
+
endDate: request.query?.endDate
|
|
335
|
+
}, request.query?.cursor, Coerce.integer(request.query?.limit));
|
|
336
|
+
return {
|
|
337
|
+
body: {
|
|
338
|
+
entries: result.entries,
|
|
339
|
+
cursor: result.cursor
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=entityStorageAuthenticationAuditRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationAuditRoutes.js","sourceRoot":"","sources":["../../../src/routes/entityStorageAuthenticationAuditRoutes.ts"],"names":[],"mappings":"AAYA,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAOb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAC;AAE7E;;GAEG;AACH,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAW;IAC9C;QACC,IAAI,EAAE,s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;QACjC,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM;QAC7B,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK;QAC3B,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS;QACnC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO;KAC/B,EACD,OAAO,CAAC,KAAK,EAAE,MAAM,EACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE;YACL,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;SACrB;KACD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuditCreateRequest,\n\tIAuditGetRequest,\n\tIAuditGetResponse,\n\tIAuditQueryRequest,\n\tIAuditQueryResponse,\n\tIAuditRemoveRequest,\n\tIAuditUpdateRequest,\n\tIAuthenticationAuditComponent\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag,\n\ttype IUnauthorizedResponse\n} from \"@3sixty/api-models\";\nimport { ContextIdStore } from \"@3sixty/context\";\nimport { Coerce, ComponentFactory, Guards } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HeaderTypes, HttpStatusCode, type IHttpHeaders } from \"@3sixty/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationAuditRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthenticationAudit: ITag[] = [\n\t{\n\t\tname: \"Authentication Audit\",\n\t\tdescription: \"Authentication audit endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication audit.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesAuthenticationAudit(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IAuditCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"authenticationAuditCreate\",\n\t\tsummary: \"Create an authentication audit entry\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditCreate(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditCreateRequestExample\",\n\t\t\t\t\tdescription: \"The request to create an authentication audit entry.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:org1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"authenticationAuditCreateResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for creating an authentication audit entry.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: 201,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"018f0b53d5d5704fa3a06d6ed2478575\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst getRoute: IRestRoute<IAuditGetRequest, IAuditGetResponse> = {\n\t\toperationId: \"authenticationAuditGet\",\n\t\tsummary: \"Get an authentication audit entry\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditGetRequestExample\",\n\t\t\t\t\tdescription: \"The request to get an authentication audit entry.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"018f0b53d5d5704fa3a06d6ed2478575\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IAuditGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"authenticationAuditGetResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for getting an authentication audit entry.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"018f0b53d5d5704fa3a06d6ed2478575\",\n\t\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\t\tdateCreated: \"2026-01-12T09:05:23.123Z\",\n\t\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:org1\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst updateRoute: IRestRoute<IAuditUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAuditUpdate\",\n\t\tsummary: \"Update an authentication audit entry\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditUpdate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditUpdateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditUpdateRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an authentication audit entry.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"018f0b53d5d5704fa3a06d6ed2478575\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:org1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst removeRoute: IRestRoute<IAuditRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAuditRemove\",\n\t\tsummary: \"Remove an authentication audit entry\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditRemoveRequestExample\",\n\t\t\t\t\tdescription: \"The request to remove an authentication audit entry.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"018f0b53d5d5704fa3a06d6ed2478575\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst queryRoute: IRestRoute<IAuditQueryRequest, IAuditQueryResponse> = {\n\t\toperationId: \"authenticationAuditQuery\",\n\t\tsummary: \"Query authentication audit entries\",\n\t\ttag: tagsAuthenticationAudit[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAuditQuery(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAuditQueryRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"authenticationAuditQueryRequestExample\",\n\t\t\t\t\tdescription: \"The request to query authentication audit entries.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\tstartDate: \"2026-01-01T00:00:00.000Z\",\n\t\t\t\t\t\t\tendDate: \"2026-01-31T23:59:59.999Z\",\n\t\t\t\t\t\t\tlimit: \"50\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IAuditQueryResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"authenticationAuditQueryResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for querying authentication audit entries.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentries: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"018f0b53d5d5704fa3a06d6ed2478575\",\n\t\t\t\t\t\t\t\t\t\tactorId: \"user@example.com\",\n\t\t\t\t\t\t\t\t\t\tdateCreated: \"2026-01-12T09:05:23.123Z\",\n\t\t\t\t\t\t\t\t\t\tevent: \"login-success\",\n\t\t\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:org1\"\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"next-cursor\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\treturn [createRoute, getRoute, updateRoute, removeRoute, queryRoute];\n}\n\n/**\n * Create an authentication audit entry.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name to use for the location header.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAuditCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditCreateRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<IAuditCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAuditCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tconst id = await component.create(request.body);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\tid,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * Get an authentication audit entry.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAuditGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditGetRequest\n): Promise<IAuditGetResponse> {\n\tGuards.object<IAuditGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAuditGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tconst entry = await component.get(request.pathParams.id);\n\n\treturn {\n\t\tbody: entry\n\t};\n}\n\n/**\n * Update an authentication audit entry.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAuditUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAuditUpdateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAuditUpdateRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAuditUpdateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tawait component.update(request.pathParams.id, request.body);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Remove an authentication audit entry.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAuditRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAuditRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAuditRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tawait component.remove(request.pathParams.id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Query authentication audit entries.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAuditQuery(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAuditQueryRequest\n): Promise<IAuditQueryResponse> {\n\tGuards.object<IAuditQueryRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IAuthenticationAuditComponent>(componentName);\n\tconst result = await component.query(\n\t\t{\n\t\t\tactorId: request.query?.actorId,\n\t\t\torganizationId: request.query?.organizationId,\n\t\t\ttenantId: request.query?.tenantId,\n\t\t\tnodeId: request.query?.nodeId,\n\t\t\tevent: request.query?.event,\n\t\t\tstartDate: request.query?.startDate,\n\t\t\tendDate: request.query?.endDate\n\t\t},\n\t\trequest.query?.cursor,\n\t\tCoerce.integer(request.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: {\n\t\t\tentries: result.entries,\n\t\t\tcursor: result.cursor\n\t\t}\n\t};\n}\n"]}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { ComponentFactory, Guards } from "@3sixty/core";
|
|
2
|
+
import { HttpStatusCode } from "@3sixty/web";
|
|
3
|
+
/**
|
|
4
|
+
* The source used when communicating about these routes.
|
|
5
|
+
*/
|
|
6
|
+
const ROUTES_SOURCE = "authenticationRoutes";
|
|
7
|
+
/**
|
|
8
|
+
* The tag to associate with the routes.
|
|
9
|
+
*/
|
|
10
|
+
export const tagsAuthentication = [
|
|
11
|
+
{
|
|
12
|
+
name: "Authentication",
|
|
13
|
+
description: "Authentication endpoints for the REST server."
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* The REST routes for authentication.
|
|
18
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
19
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
20
|
+
* @returns The generated routes.
|
|
21
|
+
*/
|
|
22
|
+
export function generateRestRoutesAuthentication(baseRouteName, componentName) {
|
|
23
|
+
const loginRoute = {
|
|
24
|
+
operationId: "authenticationLogin",
|
|
25
|
+
summary: "Login to the server",
|
|
26
|
+
tag: tagsAuthentication[0].name,
|
|
27
|
+
method: "POST",
|
|
28
|
+
path: `${baseRouteName}/login`,
|
|
29
|
+
handler: async (httpRequestContext, request) => authenticationLogin(httpRequestContext, componentName, request),
|
|
30
|
+
requestType: {
|
|
31
|
+
type: "ILoginRequest",
|
|
32
|
+
examples: [
|
|
33
|
+
{
|
|
34
|
+
id: "loginRequestExample",
|
|
35
|
+
description: "The request to login to the server.",
|
|
36
|
+
request: {
|
|
37
|
+
body: {
|
|
38
|
+
email: "user@example.com",
|
|
39
|
+
password: "MyPassword123!"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
responseType: [
|
|
46
|
+
{
|
|
47
|
+
type: "ILoginResponse",
|
|
48
|
+
examples: [
|
|
49
|
+
{
|
|
50
|
+
id: "loginResponseExample",
|
|
51
|
+
description: "The response for the login request.",
|
|
52
|
+
response: {
|
|
53
|
+
body: {
|
|
54
|
+
expiry: 1722514341067
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "IUnauthorizedResponse"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
skipAuth: true
|
|
65
|
+
};
|
|
66
|
+
const logoutRoute = {
|
|
67
|
+
operationId: "authenticationLogout",
|
|
68
|
+
summary: "Logout from the server",
|
|
69
|
+
tag: tagsAuthentication[0].name,
|
|
70
|
+
method: "POST",
|
|
71
|
+
path: `${baseRouteName}/logout`,
|
|
72
|
+
handler: async (httpRequestContext, request) => authenticationLogout(httpRequestContext, componentName, request),
|
|
73
|
+
requestType: {
|
|
74
|
+
type: "ILogoutRequest",
|
|
75
|
+
examples: [
|
|
76
|
+
{
|
|
77
|
+
id: "logoutRequestExample",
|
|
78
|
+
description: "The request to logout from the server.",
|
|
79
|
+
request: {
|
|
80
|
+
body: {
|
|
81
|
+
token: "eyJhbGciOiJIU...sw5c"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
responseType: [
|
|
88
|
+
{
|
|
89
|
+
type: "INoContentResponse"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
const refreshTokenRoute = {
|
|
94
|
+
operationId: "authenticationRefreshToken",
|
|
95
|
+
summary: "Refresh an authentication token",
|
|
96
|
+
tag: tagsAuthentication[0].name,
|
|
97
|
+
method: "POST",
|
|
98
|
+
path: `${baseRouteName}/refresh`,
|
|
99
|
+
handler: async (httpRequestContext, request) => authenticationRefreshToken(httpRequestContext, componentName, request),
|
|
100
|
+
requestType: {
|
|
101
|
+
type: "IRefreshTokenRequest",
|
|
102
|
+
examples: [
|
|
103
|
+
{
|
|
104
|
+
id: "refreshTokenRequestExample",
|
|
105
|
+
description: "The request to refresh an auth token.",
|
|
106
|
+
request: {
|
|
107
|
+
body: {
|
|
108
|
+
token: "eyJhbGciOiJIU...sw5c"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
responseType: [
|
|
115
|
+
{
|
|
116
|
+
type: "IRefreshTokenResponse",
|
|
117
|
+
examples: [
|
|
118
|
+
{
|
|
119
|
+
id: "refreshTokenResponseExample",
|
|
120
|
+
description: "The response for the refresh token request.",
|
|
121
|
+
response: {
|
|
122
|
+
body: {
|
|
123
|
+
expiry: 1722514341067
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: "IUnauthorizedResponse"
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
const updatePasswordRoute = {
|
|
135
|
+
operationId: "authenticationUpdatePassword",
|
|
136
|
+
summary: "Update the current user's password",
|
|
137
|
+
tag: tagsAuthentication[0].name,
|
|
138
|
+
method: "PUT",
|
|
139
|
+
path: `${baseRouteName}/password`,
|
|
140
|
+
handler: async (httpRequestContext, request) => authenticationUpdatePassword(httpRequestContext, componentName, request),
|
|
141
|
+
requestType: {
|
|
142
|
+
type: "IUpdatePasswordRequest",
|
|
143
|
+
examples: [
|
|
144
|
+
{
|
|
145
|
+
id: "updatePasswordRequestExample",
|
|
146
|
+
description: "The request to update the current user's password.",
|
|
147
|
+
request: {
|
|
148
|
+
body: {
|
|
149
|
+
currentPassword: "MyNewPassword123!",
|
|
150
|
+
newPassword: "MyNewPassword123!"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
responseType: [
|
|
157
|
+
{
|
|
158
|
+
type: "INoContentResponse"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
type: "IUnauthorizedResponse"
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
};
|
|
165
|
+
return [loginRoute, logoutRoute, refreshTokenRoute, updatePasswordRoute];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Login to the server.
|
|
169
|
+
* @param httpRequestContext The request context for the API.
|
|
170
|
+
* @param componentName The name of the component to use in the routes.
|
|
171
|
+
* @param request The request.
|
|
172
|
+
* @returns The response object with additional http response properties.
|
|
173
|
+
*/
|
|
174
|
+
export async function authenticationLogin(httpRequestContext, componentName, request) {
|
|
175
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
176
|
+
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
177
|
+
const component = ComponentFactory.get(componentName);
|
|
178
|
+
const result = await component.login(request.body.email, request.body.password);
|
|
179
|
+
// Need to give a hint to any auth processors about the operation
|
|
180
|
+
// in case they need to manipulate the response
|
|
181
|
+
httpRequestContext.processorState.authOperation = "login";
|
|
182
|
+
httpRequestContext.processorState.authToken = result.token;
|
|
183
|
+
return {
|
|
184
|
+
body: {
|
|
185
|
+
expiry: result.expiry
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Logout from the server.
|
|
191
|
+
* @param httpRequestContext The request context for the API.
|
|
192
|
+
* @param componentName The name of the component to use in the routes.
|
|
193
|
+
* @param request The request.
|
|
194
|
+
* @returns The response object with additional http response properties.
|
|
195
|
+
*/
|
|
196
|
+
export async function authenticationLogout(httpRequestContext, componentName, request) {
|
|
197
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
198
|
+
const component = ComponentFactory.get(componentName);
|
|
199
|
+
await component.logout(request.body?.token);
|
|
200
|
+
// Need to give a hint to any auth processors about the operation
|
|
201
|
+
// in case they need to manipulate the response
|
|
202
|
+
httpRequestContext.processorState.authOperation = "logout";
|
|
203
|
+
return {
|
|
204
|
+
statusCode: HttpStatusCode.noContent
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Refresh the login token.
|
|
209
|
+
* @param httpRequestContext The request context for the API.
|
|
210
|
+
* @param componentName The name of the component to use in the routes.
|
|
211
|
+
* @param request The request.
|
|
212
|
+
* @returns The response object with additional http response properties.
|
|
213
|
+
*/
|
|
214
|
+
export async function authenticationRefreshToken(httpRequestContext, componentName, request) {
|
|
215
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
216
|
+
const component = ComponentFactory.get(componentName);
|
|
217
|
+
// If the token is not in the body, then maybe an auth processor has extracted it
|
|
218
|
+
// and stored it in the processor state
|
|
219
|
+
const token = request.body?.token ?? httpRequestContext.processorState.authToken;
|
|
220
|
+
const result = await component.refresh(token);
|
|
221
|
+
// Need to give a hint to any auth processors about the operation
|
|
222
|
+
// in case they need to manipulate the response
|
|
223
|
+
httpRequestContext.processorState.authOperation = "refresh";
|
|
224
|
+
httpRequestContext.processorState.authToken = result.token;
|
|
225
|
+
return {
|
|
226
|
+
body: {
|
|
227
|
+
expiry: result.expiry
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Update the user's password.
|
|
233
|
+
* @param httpRequestContext The request context for the API.
|
|
234
|
+
* @param componentName The name of the component to use in the routes.
|
|
235
|
+
* @param request The request.
|
|
236
|
+
* @returns The response object with additional http response properties.
|
|
237
|
+
*/
|
|
238
|
+
export async function authenticationUpdatePassword(httpRequestContext, componentName, request) {
|
|
239
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
240
|
+
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
241
|
+
const component = ComponentFactory.get(componentName);
|
|
242
|
+
await component.updatePassword(request.body.currentPassword, request.body.newPassword);
|
|
243
|
+
return {
|
|
244
|
+
statusCode: HttpStatusCode.noContent
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=entityStorageAuthenticationRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationRoutes.js","sourceRoot":"","sources":["../../../src/routes/entityStorageAuthenticationRoutes.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACzC;QACC,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,+CAA+C;KAC5D;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,UAAU,GAA8C;QAC7D,WAAW,EAAE,qBAAqB;QAClC,OAAO,EAAE,qBAAqB;QAC9B,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,QAAQ;QAC9B,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,mBAAmB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QAChE,WAAW,EAAE;YACZ,IAAI,iBAAyB;YAC7B,QAAQ,EAAE;gBACT;oBACC,EAAE,EAAE,qBAAqB;oBACzB,WAAW,EAAE,qCAAqC;oBAClD,OAAO,EAAE;wBACR,IAAI,EAAE;4BACL,KAAK,EAAE,kBAAkB;4BACzB,QAAQ,EAAE,gBAAgB;yBAC1B;qBACD;iBACD;aACD;SACD;QACD,YAAY,EAAE;YACb;gBACC,IAAI,kBAA0B;gBAC9B,QAAQ,EAAE;oBACT;wBACC,EAAE,EAAE,sBAAsB;wBAC1B,WAAW,EAAE,qCAAqC;wBAClD,QAAQ,EAAE;4BACT,IAAI,EAA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KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,KAAK,IAAK,kBAAkB,CAAC,cAAc,CAAC,SAAoB,CAAC;IAC7F,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE9C,iEAAiE;IACjE,+CAA+C;IAC/C,kBAAkB,CAAC,cAAc,CAAC,aAAa,GAAG,SAAS,CAAC;IAC5D,kBAAkB,CAAC,cAAc,CAAC,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC;IAE3D,OAAO;QACN,IAAI,EAAE;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;SACrB;KACD,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CACjD,kBAAuC,EACvC,aAAqB,EACrB,OAA+B;IAE/B,MAAM,CAAC,MAAM,CAAyB,aAAa,aAAmB,OAAO,CAAC,CAAC;IAC/E,MAAM,CAAC,MAAM,CAAiC,aAAa,kBAAwB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjG,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAEhF,MAAM,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvF,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationComponent,\n\tILoginRequest,\n\tILoginResponse,\n\tILogoutRequest,\n\tIRefreshTokenRequest,\n\tIRefreshTokenResponse,\n\tIUpdatePasswordRequest\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport type {\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tIRestRouteResponseOptions,\n\tITag,\n\tIUnauthorizedResponse\n} from \"@3sixty/api-models\";\nimport { ComponentFactory, Guards } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HttpStatusCode } from \"@3sixty/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthentication: ITag[] = [\n\t{\n\t\tname: \"Authentication\",\n\t\tdescription: \"Authentication endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesAuthentication(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst loginRoute: IRestRoute<ILoginRequest, ILoginResponse> = {\n\t\toperationId: \"authenticationLogin\",\n\t\tsummary: \"Login to the server\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/login`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationLogin(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ILoginRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"loginRequestExample\",\n\t\t\t\t\tdescription: \"The request to login to the server.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\tpassword: \"MyPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ILoginResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"loginResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the login request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\texpiry: 1722514341067\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\tskipAuth: true\n\t};\n\n\tconst logoutRoute: IRestRoute<ILogoutRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationLogout\",\n\t\tsummary: \"Logout from the server\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/logout`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationLogout(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ILogoutRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"logoutRequestExample\",\n\t\t\t\t\tdescription: \"The request to logout from the server.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\ttoken: \"eyJhbGciOiJIU...sw5c\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst refreshTokenRoute: IRestRoute<IRefreshTokenRequest, IRefreshTokenResponse> = {\n\t\toperationId: \"authenticationRefreshToken\",\n\t\tsummary: \"Refresh an authentication token\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/refresh`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationRefreshToken(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IRefreshTokenRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"refreshTokenRequestExample\",\n\t\t\t\t\tdescription: \"The request to refresh an auth token.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\ttoken: \"eyJhbGciOiJIU...sw5c\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IRefreshTokenResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"refreshTokenResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the refresh token request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\texpiry: 1722514341067\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst updatePasswordRoute: IRestRoute<IUpdatePasswordRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationUpdatePassword\",\n\t\tsummary: \"Update the current user's password\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/password`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationUpdatePassword(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IUpdatePasswordRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updatePasswordRequestExample\",\n\t\t\t\t\tdescription: \"The request to update the current user's password.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tcurrentPassword: \"MyNewPassword123!\",\n\t\t\t\t\t\t\tnewPassword: \"MyNewPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [loginRoute, logoutRoute, refreshTokenRoute, updatePasswordRoute];\n}\n\n/**\n * Login to the server.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationLogin(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ILoginRequest\n): Promise<ILoginResponse & IRestRouteResponseOptions> {\n\tGuards.object<ILoginRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ILoginRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tconst result = await component.login(request.body.email, request.body.password);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"login\";\n\thttpRequestContext.processorState.authToken = result.token;\n\n\treturn {\n\t\tbody: {\n\t\t\texpiry: result.expiry\n\t\t}\n\t};\n}\n\n/**\n * Logout from the server.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationLogout(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ILogoutRequest\n): Promise<INoContentResponse & IRestRouteResponseOptions> {\n\tGuards.object<ILogoutRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tawait component.logout(request.body?.token);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"logout\";\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Refresh the login token.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationRefreshToken(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IRefreshTokenRequest\n): Promise<IRefreshTokenResponse & IRestRouteResponseOptions> {\n\tGuards.object<IRefreshTokenRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\n\t// If the token is not in the body, then maybe an auth processor has extracted it\n\t// and stored it in the processor state\n\tconst token = request.body?.token ?? (httpRequestContext.processorState.authToken as string);\n\tconst result = await component.refresh(token);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"refresh\";\n\thttpRequestContext.processorState.authToken = result.token;\n\n\treturn {\n\t\tbody: {\n\t\t\texpiry: result.expiry\n\t\t}\n\t};\n}\n\n/**\n * Update the user's password.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationUpdatePassword(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IUpdatePasswordRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IUpdatePasswordRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IUpdatePasswordRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\n\tawait component.updatePassword(request.body.currentPassword, request.body.newPassword);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|