@twin.org/api-auth-entity-storage-service 0.0.3-next.22 → 0.0.3-next.24
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/dist/es/entities/authenticationAuditEntry.js +101 -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 +10 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js.map +1 -1
- 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 +0 -2
- package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -1
- package/dist/es/processors/authHeaderProcessor.js +18 -4
- package/dist/es/processors/authHeaderProcessor.js.map +1 -1
- package/dist/es/restEntryPoints.js +7 -0
- package/dist/es/restEntryPoints.js.map +1 -1
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js +174 -0
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js.map +1 -0
- package/dist/es/schema.js +4 -0
- package/dist/es/schema.js.map +1 -1
- package/dist/es/services/entityStorageAuthenticationAdminService.js +53 -27
- package/dist/es/services/entityStorageAuthenticationAdminService.js.map +1 -1
- package/dist/es/services/entityStorageAuthenticationAuditService.js +178 -0
- package/dist/es/services/entityStorageAuthenticationAuditService.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationRateService.js +202 -0
- package/dist/es/services/entityStorageAuthenticationRateService.js.map +1 -0
- package/dist/es/services/entityStorageAuthenticationService.js +156 -11
- package/dist/es/services/entityStorageAuthenticationService.js.map +1 -1
- package/dist/es/utils/passwordHelper.js +57 -0
- package/dist/es/utils/passwordHelper.js.map +1 -0
- package/dist/es/utils/tokenHelper.js +11 -1
- package/dist/es/utils/tokenHelper.js.map +1 -1
- package/dist/types/entities/authenticationAuditEntry.d.ts +49 -0
- package/dist/types/entities/authenticationRateEntry.d.ts +17 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/models/IAuthHeaderProcessorConstructorOptions.d.ts +5 -0
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +5 -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 +20 -0
- package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +22 -1
- package/dist/types/models/IEntityStorageAuthenticationServiceConstructorOptions.d.ts +8 -3
- package/dist/types/routes/entityStorageAuthenticationAuditRoutes.d.ts +29 -0
- package/dist/types/services/entityStorageAuthenticationAuditService.d.ts +59 -0
- package/dist/types/services/entityStorageAuthenticationRateService.d.ts +60 -0
- package/dist/types/services/entityStorageAuthenticationService.d.ts +6 -0
- package/dist/types/utils/passwordHelper.d.ts +24 -0
- package/dist/types/utils/tokenHelper.d.ts +2 -1
- package/docs/changelog.md +32 -0
- package/docs/reference/classes/AuthenticationAuditEntry.md +101 -0
- package/docs/reference/classes/AuthenticationRateEntry.md +37 -0
- package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +4 -4
- package/docs/reference/classes/EntityStorageAuthenticationAuditService.md +157 -0
- package/docs/reference/classes/EntityStorageAuthenticationRateService.md +227 -0
- package/docs/reference/classes/EntityStorageAuthenticationService.md +26 -0
- package/docs/reference/classes/PasswordHelper.md +74 -0
- package/docs/reference/classes/TokenHelper.md +7 -1
- package/docs/reference/functions/authenticationAuditCreate.md +31 -0
- package/docs/reference/functions/authenticationAuditQuery.md +31 -0
- package/docs/reference/functions/generateRestRoutesAuthenticationAudit.md +25 -0
- package/docs/reference/index.md +13 -0
- package/docs/reference/interfaces/IAuthHeaderProcessorConstructorOptions.md +14 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +14 -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 +39 -0
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +57 -1
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md +18 -4
- package/docs/reference/variables/tagsAuthenticationAudit.md +5 -0
- package/locales/en.json +13 -2
- package/package.json +5 -4
|
@@ -43,10 +43,11 @@ export class TokenHelper {
|
|
|
43
43
|
* @param signingKeyName The signing key name.
|
|
44
44
|
* @param token The token to verify.
|
|
45
45
|
* @param requiredScopes The required scopes.
|
|
46
|
+
* @param verifyUser A function to verify the user identity and organization, which can be used to check if the user is still active or not.
|
|
46
47
|
* @returns The verified details.
|
|
47
48
|
* @throws UnauthorizedError if the token is missing, invalid or expired.
|
|
48
49
|
*/
|
|
49
|
-
static async verify(vaultConnector, signingKeyName, token, requiredScopes) {
|
|
50
|
+
static async verify(vaultConnector, signingKeyName, token, requiredScopes, verifyUser) {
|
|
50
51
|
if (!Is.stringValue(token)) {
|
|
51
52
|
throw new UnauthorizedError(TokenHelper.CLASS_NAME, "missing");
|
|
52
53
|
}
|
|
@@ -62,6 +63,15 @@ export class TokenHelper {
|
|
|
62
63
|
decoded.payload.exp < Math.trunc(Date.now() / 1000)) {
|
|
63
64
|
throw new UnauthorizedError(TokenHelper.CLASS_NAME, "expired");
|
|
64
65
|
}
|
|
66
|
+
if (Is.function(verifyUser)) {
|
|
67
|
+
const userVerified = await verifyUser(decoded.payload.sub, decoded.payload.org);
|
|
68
|
+
if (!userVerified.includes("user")) {
|
|
69
|
+
throw new UnauthorizedError(TokenHelper.CLASS_NAME, "userNotVerified");
|
|
70
|
+
}
|
|
71
|
+
else if (!userVerified.includes("organization")) {
|
|
72
|
+
throw new UnauthorizedError(TokenHelper.CLASS_NAME, "organizationNotVerified");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
65
75
|
if (Is.arrayValue(requiredScopes)) {
|
|
66
76
|
const tokenScopes = Is.stringValue(decoded.payload.scope)
|
|
67
77
|
? decoded.payload.scope.split(",")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenHelper.js","sourceRoot":"","sources":["../../../src/utils/tokenHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAwB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EAIX,GAAG,EACH,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,OAAO,WAAW;IACvB;;OAEG;IACI,MAAM,CAAU,UAAU,iBAAiC;IAElE;;;;;;;;;;OAUG;IACI,MAAM,CAAC,KAAK,CAAC,WAAW,CAC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\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, UnauthorizedError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { type IVaultConnector, VaultConnectorHelper } from \"@twin.org/vault-models\";\nimport {\n\tCookieHelper,\n\tHeaderHelper,\n\tHeaderTypes,\n\ttype IHttpHeaders,\n\ttype IJwtHeader,\n\ttype IJwtPayload,\n\tJwt\n} from \"@twin.org/web\";\n\n/**\n * Helper class for token operations.\n */\nexport class TokenHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TokenHelper>();\n\n\t/**\n\t * Create a new token.\n\t * @param vaultConnector The vault connector.\n\t * @param signingKeyName The signing key name.\n\t * @param userIdentity The subject for the token.\n\t * @param organizationIdentity The organization for the token.\n\t * @param tenantId The tenant id for the token.\n\t * @param ttlMinutes The time to live for the token in minutes.\n\t * @param scope The scopes for the token.\n\t * @returns The new token and its expiry date.\n\t */\n\tpublic static async createToken(\n\t\tvaultConnector: IVaultConnector,\n\t\tsigningKeyName: string,\n\t\tuserIdentity: string,\n\t\torganizationIdentity: string | undefined,\n\t\ttenantId: string | undefined,\n\t\tttlMinutes: number,\n\t\tscope?: string\n\t): Promise<{\n\t\ttoken: string;\n\t\texpiry: number;\n\t}> {\n\t\tconst nowSeconds = Math.trunc(Date.now() / 1000);\n\t\tconst ttlSeconds = ttlMinutes * 60;\n\n\t\tconst jwt = await Jwt.encodeWithSigner(\n\t\t\t{ alg: \"EdDSA\" },\n\t\t\t{\n\t\t\t\tsub: userIdentity,\n\t\t\t\torg: organizationIdentity,\n\t\t\t\ttid: tenantId,\n\t\t\t\texp: nowSeconds + ttlSeconds,\n\t\t\t\tscope\n\t\t\t},\n\t\t\tasync (header, payload) =>\n\t\t\t\tVaultConnectorHelper.jwtSigner(vaultConnector, signingKeyName, header, payload)\n\t\t);\n\n\t\treturn {\n\t\t\ttoken: jwt,\n\t\t\texpiry: (nowSeconds + ttlSeconds) * 1000\n\t\t};\n\t}\n\n\t/**\n\t * Verify the token.\n\t * @param vaultConnector The vault connector.\n\t * @param signingKeyName The signing key name.\n\t * @param token The token to verify.\n\t * @param requiredScopes The required scopes.\n\t * @param verifyUser A function to verify the user identity and organization, which can be used to check if the user is still active or not.\n\t * @returns The verified details.\n\t * @throws UnauthorizedError if the token is missing, invalid or expired.\n\t */\n\tpublic static async verify(\n\t\tvaultConnector: IVaultConnector,\n\t\tsigningKeyName: string,\n\t\ttoken: string | undefined,\n\t\trequiredScopes?: string[],\n\t\tverifyUser?: (userIdentity: string, organizationIdentity: string) => Promise<string[]>\n\t): Promise<{\n\t\theader: IJwtHeader;\n\t\tpayload: IJwtPayload;\n\t}> {\n\t\tif (!Is.stringValue(token)) {\n\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"missing\");\n\t\t}\n\n\t\tconst decoded = await Jwt.verifyWithVerifier(token, async t =>\n\t\t\tVaultConnectorHelper.jwtVerifier(vaultConnector, signingKeyName, t)\n\t\t);\n\n\t\t// If some of the header/payload data is not properly populated then it is unauthorized.\n\t\tif (!Is.stringValue(decoded.payload.sub)) {\n\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"payloadMissingSubject\");\n\t\t} else if (!Is.stringValue(decoded.payload.org)) {\n\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"payloadMissingOrganization\");\n\t\t} else if (\n\t\t\t!Is.empty(decoded.payload?.exp) &&\n\t\t\tdecoded.payload.exp < Math.trunc(Date.now() / 1000)\n\t\t) {\n\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"expired\");\n\t\t}\n\n\t\tif (Is.function(verifyUser)) {\n\t\t\tconst userVerified = await verifyUser(decoded.payload.sub, decoded.payload.org);\n\t\t\tif (!userVerified.includes(\"user\")) {\n\t\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"userNotVerified\");\n\t\t\t} else if (!userVerified.includes(\"organization\")) {\n\t\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"organizationNotVerified\");\n\t\t\t}\n\t\t}\n\n\t\tif (Is.arrayValue(requiredScopes)) {\n\t\t\tconst tokenScopes = Is.stringValue(decoded.payload.scope)\n\t\t\t\t? decoded.payload.scope.split(\",\")\n\t\t\t\t: [];\n\n\t\t\tfor (const requiredScope of requiredScopes) {\n\t\t\t\tif (!tokenScopes.includes(requiredScope)) {\n\t\t\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"insufficientScopes\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\theader: decoded.header,\n\t\t\tpayload: decoded.payload\n\t\t};\n\t}\n\n\t/**\n\t * Extract the auth token from the headers, either from the authorization header or the cookie header.\n\t * @param headers The headers to extract the token from.\n\t * @param cookieName The name of the cookie to extract the token from.\n\t * @returns The token if found.\n\t */\n\tpublic static extractTokenFromHeaders(\n\t\theaders?: IHttpHeaders,\n\t\tcookieName?: string\n\t):\n\t\t| {\n\t\t\t\ttoken: string;\n\t\t\t\tlocation: \"authorization\" | \"cookie\";\n\t\t }\n\t\t| undefined {\n\t\tconst authHeader = headers?.[HeaderTypes.Authorization];\n\t\tconst cookiesHeader = headers?.[HeaderTypes.Cookie];\n\n\t\tconst bearerToken = HeaderHelper.extractBearer(authHeader);\n\t\tif (Is.stringValue(bearerToken)) {\n\t\t\treturn {\n\t\t\t\ttoken: bearerToken,\n\t\t\t\tlocation: \"authorization\"\n\t\t\t};\n\t\t} else if (Is.notEmpty(cookiesHeader) && Is.stringValue(cookieName)) {\n\t\t\tconst value = CookieHelper.getCookieFromHeaders(cookiesHeader, cookieName);\n\t\t\tif (Is.stringValue(value)) {\n\t\t\t\treturn {\n\t\t\t\t\ttoken: value,\n\t\t\t\t\tlocation: \"cookie\"\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for authentication audit entries.
|
|
3
|
+
*/
|
|
4
|
+
export declare class AuthenticationAuditEntry {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier for the audit entry.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The timestamp of the audit entry in ISO 8601 format.
|
|
11
|
+
*/
|
|
12
|
+
dateCreated: string;
|
|
13
|
+
/**
|
|
14
|
+
* The audit event that occurred.
|
|
15
|
+
*/
|
|
16
|
+
event: string;
|
|
17
|
+
/**
|
|
18
|
+
* The actor identifier, could be e-mail, username, or other unique identifier.
|
|
19
|
+
*/
|
|
20
|
+
actorId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The node identifier associated with the audit entry, if applicable.
|
|
23
|
+
*/
|
|
24
|
+
nodeId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The organization identifier associated with the audit entry, if applicable.
|
|
27
|
+
*/
|
|
28
|
+
organizationId?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The tenant identifier associated with the audit entry, if applicable.
|
|
31
|
+
*/
|
|
32
|
+
tenantId?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The hashed IP addresses of the client.
|
|
35
|
+
*/
|
|
36
|
+
ipAddressHashes?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* The user agent string of the client.
|
|
39
|
+
*/
|
|
40
|
+
userAgent?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The correlation ID for request tracing.
|
|
43
|
+
*/
|
|
44
|
+
correlationId?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Additional data related to the audit entry, such as IP address, user agent, etc.
|
|
47
|
+
*/
|
|
48
|
+
data?: unknown;
|
|
49
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class defining the storage for authentication rate entries.
|
|
3
|
+
*/
|
|
4
|
+
export declare class AuthenticationRateEntry {
|
|
5
|
+
/**
|
|
6
|
+
* The id for the rate entry.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* Array of ISO date strings representing timestamps of failed attempts.
|
|
11
|
+
*/
|
|
12
|
+
timestamps: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Last modification time in ISO date format.
|
|
15
|
+
*/
|
|
16
|
+
dateModified: string;
|
|
17
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
export * from "./entities/authenticationAuditEntry.js";
|
|
2
|
+
export * from "./entities/authenticationRateEntry.js";
|
|
1
3
|
export * from "./entities/authenticationUser.js";
|
|
2
4
|
export * from "./models/IAuthHeaderProcessorConfig.js";
|
|
3
5
|
export * from "./models/IAuthHeaderProcessorConstructorOptions.js";
|
|
4
6
|
export * from "./models/IEntityStorageAuthenticationAdminServiceConfig.js";
|
|
5
7
|
export * from "./models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js";
|
|
8
|
+
export * from "./models/IEntityStorageAuthenticationAuditServiceConfig.js";
|
|
9
|
+
export * from "./models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js";
|
|
10
|
+
export * from "./models/IEntityStorageAuthenticationRateServiceConfig.js";
|
|
11
|
+
export * from "./models/IEntityStorageAuthenticationRateServiceConstructorOptions.js";
|
|
6
12
|
export * from "./models/IEntityStorageAuthenticationServiceConfig.js";
|
|
7
13
|
export * from "./models/IEntityStorageAuthenticationServiceConstructorOptions.js";
|
|
8
14
|
export * from "./processors/authHeaderProcessor.js";
|
|
9
15
|
export * from "./restEntryPoints.js";
|
|
10
16
|
export * from "./routes/entityStorageAuthenticationAdminRoutes.js";
|
|
17
|
+
export * from "./routes/entityStorageAuthenticationAuditRoutes.js";
|
|
11
18
|
export * from "./routes/entityStorageAuthenticationRoutes.js";
|
|
12
19
|
export * from "./schema.js";
|
|
13
20
|
export * from "./services/entityStorageAuthenticationAdminService.js";
|
|
21
|
+
export * from "./services/entityStorageAuthenticationAuditService.js";
|
|
22
|
+
export * from "./services/entityStorageAuthenticationRateService.js";
|
|
14
23
|
export * from "./services/entityStorageAuthenticationService.js";
|
|
15
24
|
export * from "./utils/tokenHelper.js";
|
|
25
|
+
export * from "./utils/passwordHelper.js";
|
|
@@ -3,6 +3,11 @@ import type { IAuthHeaderProcessorConfig } from "./IAuthHeaderProcessorConfig.js
|
|
|
3
3
|
* Options for the AuthHeaderProcessor constructor.
|
|
4
4
|
*/
|
|
5
5
|
export interface IAuthHeaderProcessorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The admin service.
|
|
8
|
+
* @default authentication-admin
|
|
9
|
+
*/
|
|
10
|
+
authenticationAdminServiceType?: string;
|
|
6
11
|
/**
|
|
7
12
|
* The vault for the private keys.
|
|
8
13
|
* @default vault
|
|
@@ -8,6 +8,11 @@ export interface IEntityStorageAuthenticationAdminServiceConstructorOptions {
|
|
|
8
8
|
* @default authentication-user
|
|
9
9
|
*/
|
|
10
10
|
userEntityStorageType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The audit service.
|
|
13
|
+
* @default authentication-audit
|
|
14
|
+
*/
|
|
15
|
+
authenticationAuditServiceType?: string;
|
|
11
16
|
/**
|
|
12
17
|
* The configuration for the authentication.
|
|
13
18
|
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config for the EntityStorageAuthenticationAuditService constructor.
|
|
3
|
+
*/
|
|
4
|
+
export interface IEntityStorageAuthenticationAuditServiceConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The server-side salt for hashing IP addresses in audit logs, if configured.
|
|
7
|
+
*/
|
|
8
|
+
ipHashSalt?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IEntityStorageAuthenticationAuditServiceConfig } from "./IEntityStorageAuthenticationAuditServiceConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the EntityStorageAuthenticationAuditService constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IEntityStorageAuthenticationAuditServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The entity storage for the audit entries.
|
|
8
|
+
* @default authentication-audit-entry
|
|
9
|
+
*/
|
|
10
|
+
authenticationAuditEntryStorageType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The configuration for the authentication audit service.
|
|
13
|
+
*/
|
|
14
|
+
config?: IEntityStorageAuthenticationAuditServiceConfig;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IEntityStorageAuthenticationRateServiceConfig } from "./IEntityStorageAuthenticationRateServiceConfig.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the EntityStorageAuthenticationRateService constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IEntityStorageAuthenticationRateServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The entity storage for authentication rate entries.
|
|
8
|
+
* @default authentication-rate-entry
|
|
9
|
+
*/
|
|
10
|
+
authenticationRateEntryStorageType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The task scheduler component type.
|
|
13
|
+
* @default task-scheduler
|
|
14
|
+
*/
|
|
15
|
+
taskSchedulerComponentType?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The configuration for the authentication rate service.
|
|
18
|
+
*/
|
|
19
|
+
config?: IEntityStorageAuthenticationRateServiceConfig;
|
|
20
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IAuthenticationRateActionConfig } from "@twin.org/api-auth-entity-storage-models";
|
|
1
2
|
/**
|
|
2
3
|
* Configuration for the entity storage authentication service.
|
|
3
4
|
*/
|
|
@@ -9,7 +10,27 @@ export interface IEntityStorageAuthenticationServiceConfig {
|
|
|
9
10
|
signingKeyName?: string;
|
|
10
11
|
/**
|
|
11
12
|
* The default time to live for the JWT.
|
|
12
|
-
* @default
|
|
13
|
+
* @default 60
|
|
13
14
|
*/
|
|
14
15
|
defaultTtlMinutes?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The minimum password length for new password validation.
|
|
18
|
+
* @default 8
|
|
19
|
+
*/
|
|
20
|
+
minPasswordLength?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Optional override for login failure rate limit.
|
|
23
|
+
* @default { maxAttempts: 5, windowMinutes: 15 }
|
|
24
|
+
*/
|
|
25
|
+
loginRateLimit?: IAuthenticationRateActionConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Optional override for password change rate limit.
|
|
28
|
+
* @default { maxAttempts: 5, windowMinutes: 15 }
|
|
29
|
+
*/
|
|
30
|
+
passwordChangeRateLimit?: IAuthenticationRateActionConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Optional override for token refresh rate limit.
|
|
33
|
+
* @default { maxAttempts: 30, windowMinutes: 60 }
|
|
34
|
+
*/
|
|
35
|
+
tokenRefreshRateLimit?: IAuthenticationRateActionConfig;
|
|
15
36
|
}
|
|
@@ -14,10 +14,15 @@ export interface IEntityStorageAuthenticationServiceConstructorOptions {
|
|
|
14
14
|
*/
|
|
15
15
|
vaultConnectorType?: string;
|
|
16
16
|
/**
|
|
17
|
-
* The
|
|
18
|
-
* @default authentication-
|
|
17
|
+
* The audit service.
|
|
18
|
+
* @default authentication-audit
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
authenticationAuditServiceType?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The rate service.
|
|
23
|
+
* @default authentication-rate
|
|
24
|
+
*/
|
|
25
|
+
authenticationRateServiceType?: string;
|
|
21
26
|
/**
|
|
22
27
|
* The configuration for the authentication.
|
|
23
28
|
*/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IAuditCreateRequest, IAuditQueryRequest, IAuditQueryResponse } from "@twin.org/api-auth-entity-storage-models";
|
|
2
|
+
import type { ICreatedResponse, IHttpRequestContext, IRestRoute, ITag } from "@twin.org/api-models";
|
|
3
|
+
/**
|
|
4
|
+
* The tag to associate with the routes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const tagsAuthenticationAudit: ITag[];
|
|
7
|
+
/**
|
|
8
|
+
* The REST routes for authentication audit.
|
|
9
|
+
* @param baseRouteName Prefix to prepend to the paths.
|
|
10
|
+
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
11
|
+
* @returns The generated routes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateRestRoutesAuthenticationAudit(baseRouteName: string, componentName: string): IRestRoute[];
|
|
14
|
+
/**
|
|
15
|
+
* Create an authentication audit entry.
|
|
16
|
+
* @param httpRequestContext The request context for the API.
|
|
17
|
+
* @param componentName The name of the component to use in the routes.
|
|
18
|
+
* @param request The request.
|
|
19
|
+
* @returns The response object with additional http response properties.
|
|
20
|
+
*/
|
|
21
|
+
export declare function authenticationAuditCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: IAuditCreateRequest): Promise<ICreatedResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Query authentication audit entries.
|
|
24
|
+
* @param httpRequestContext The request context for the API.
|
|
25
|
+
* @param componentName The name of the component to use in the routes.
|
|
26
|
+
* @param request The request.
|
|
27
|
+
* @returns The response object with additional http response properties.
|
|
28
|
+
*/
|
|
29
|
+
export declare function authenticationAuditQuery(httpRequestContext: IHttpRequestContext, componentName: string, request: IAuditQueryRequest): Promise<IAuditQueryResponse>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AuthAuditEvent, IAuthenticationAuditComponent, IAuthenticationAuditEntry } from "@twin.org/api-auth-entity-storage-models";
|
|
2
|
+
import type { IEntityStorageAuthenticationAuditServiceConstructorOptions } from "../models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the authentication audit component using entity storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EntityStorageAuthenticationAuditService implements IAuthenticationAuditComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of EntityStorageAuthenticationAuditService.
|
|
13
|
+
* @param options The dependencies for the identity connector.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: IEntityStorageAuthenticationAuditServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the class name of the component.
|
|
18
|
+
* @returns The class name of the component.
|
|
19
|
+
*/
|
|
20
|
+
className(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new audit entry.
|
|
23
|
+
* @param entry The audit entry to be logged.
|
|
24
|
+
* @returns The unique identifier of the created audit entry.
|
|
25
|
+
*/
|
|
26
|
+
create(entry: Omit<IAuthenticationAuditEntry, "id" | "dateCreated">): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Query the audit entries.
|
|
29
|
+
* @param options The query options.
|
|
30
|
+
* @param options.actorId The actor identifier to filter the audit entries, optional.
|
|
31
|
+
* @param options.organizationId The organization identifier to filter the audit entries, optional.
|
|
32
|
+
* @param options.tenantId The tenant identifier to filter the audit entries, optional.
|
|
33
|
+
* @param options.nodeId The node identifier to filter the audit entries, optional.
|
|
34
|
+
* @param options.event The audit event to filter the audit entries, optional.
|
|
35
|
+
* @param options.startDate The start date to filter the audit entries, optional.
|
|
36
|
+
* @param options.endDate The end date to filter the audit entries, optional.
|
|
37
|
+
* @param cursor The cursor for pagination.
|
|
38
|
+
* @param limit The maximum number of entries to return.
|
|
39
|
+
* @returns The audit entries.
|
|
40
|
+
*/
|
|
41
|
+
query(options?: {
|
|
42
|
+
actorId?: string;
|
|
43
|
+
organizationId?: string;
|
|
44
|
+
tenantId?: string;
|
|
45
|
+
nodeId?: string;
|
|
46
|
+
event?: AuthAuditEvent | string;
|
|
47
|
+
startDate?: string;
|
|
48
|
+
endDate?: string;
|
|
49
|
+
}, cursor?: string, limit?: number): Promise<{
|
|
50
|
+
entries: IAuthenticationAuditEntry[];
|
|
51
|
+
cursor?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Hash a list of IP addresses using SHA-256.
|
|
55
|
+
* @param ipAddresses The IP addresses to hash.
|
|
56
|
+
* @returns The hexadecimal hashes of the salted IPs.
|
|
57
|
+
*/
|
|
58
|
+
private hashIpAddresses;
|
|
59
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { IAuthenticationRateActionConfig, IAuthenticationRateComponent } from "@twin.org/api-auth-entity-storage-models";
|
|
2
|
+
import type { IEntityStorageAuthenticationRateServiceConstructorOptions } from "../models/IEntityStorageAuthenticationRateServiceConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the authentication rate component using entity storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EntityStorageAuthenticationRateService implements IAuthenticationRateComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Runtime name for the class.
|
|
9
|
+
*/
|
|
10
|
+
static readonly CLASS_NAME: string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of EntityStorageAuthenticationRateService.
|
|
13
|
+
* @param options The constructor options.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options?: IEntityStorageAuthenticationRateServiceConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Register or update rate-limit configuration for an action.
|
|
18
|
+
* @param action The action name.
|
|
19
|
+
* @param config The action configuration.
|
|
20
|
+
* @returns Nothing.
|
|
21
|
+
*/
|
|
22
|
+
registerAction(action: string, config: IAuthenticationRateActionConfig): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Unregister rate-limit configuration for an action.
|
|
25
|
+
* @param action The action name.
|
|
26
|
+
* @returns Nothing.
|
|
27
|
+
*/
|
|
28
|
+
unregisterAction(action: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the class name of the component.
|
|
31
|
+
* @returns The class name of the component.
|
|
32
|
+
*/
|
|
33
|
+
className(): string;
|
|
34
|
+
/**
|
|
35
|
+
* The service needs to be started when the application is initialized.
|
|
36
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
37
|
+
* @returns Nothing.
|
|
38
|
+
*/
|
|
39
|
+
start(nodeLoggingComponentType?: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* The component needs to be stopped when the node is closed.
|
|
42
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
43
|
+
* @returns Nothing.
|
|
44
|
+
*/
|
|
45
|
+
stop(nodeLoggingComponentType?: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Check the authentication rate for a given action and identifier.
|
|
48
|
+
* @param action The action to be checked.
|
|
49
|
+
* @param identifier The identifier to be checked.
|
|
50
|
+
* @returns The rate entry id.
|
|
51
|
+
*/
|
|
52
|
+
check(action: string, identifier: string): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Clear the authentication rate entry for the given action and identifier.
|
|
55
|
+
* @param action The action to clear.
|
|
56
|
+
* @param identifier The identifier to clear.
|
|
57
|
+
* @returns Nothing.
|
|
58
|
+
*/
|
|
59
|
+
clear(action: string, identifier: string): Promise<void>;
|
|
60
|
+
}
|
|
@@ -24,6 +24,12 @@ export declare class EntityStorageAuthenticationService implements IAuthenticati
|
|
|
24
24
|
* @returns Nothing.
|
|
25
25
|
*/
|
|
26
26
|
start(nodeLoggingComponentType?: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* The component needs to be stopped when the node is closed.
|
|
29
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
30
|
+
* @returns Nothing.
|
|
31
|
+
*/
|
|
32
|
+
stop(nodeLoggingComponentType?: string): Promise<void>;
|
|
27
33
|
/**
|
|
28
34
|
* Perform a login for the user.
|
|
29
35
|
* @param email The email address for the user.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IAuthenticationAuditComponent } from "@twin.org/api-auth-entity-storage-models";
|
|
2
|
+
import type { IEntityStorageConnector } from "@twin.org/entity-storage-models";
|
|
3
|
+
import type { AuthenticationUser } from "../entities/authenticationUser.js";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for password operations.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PasswordHelper {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
12
|
+
/**
|
|
13
|
+
* Update the password for a user.
|
|
14
|
+
* Validates password strength, verifies the current password if provided, then hashes and stores the new password and raises an audit event.
|
|
15
|
+
* @param userEntityStorage The entity storage for users.
|
|
16
|
+
* @param authenticationAuditService The optional audit service.
|
|
17
|
+
* @param user The user whose password is being updated.
|
|
18
|
+
* @param newPassword The new password to set.
|
|
19
|
+
* @param currentPassword The current password to verify against, if supplied.
|
|
20
|
+
* @param minPasswordLength Optional minimum password length for validation.
|
|
21
|
+
* @returns Nothing.
|
|
22
|
+
*/
|
|
23
|
+
static updatePassword(userEntityStorage: IEntityStorageConnector<AuthenticationUser>, authenticationAuditService: IAuthenticationAuditComponent | undefined, user: AuthenticationUser, newPassword: string, currentPassword?: string, minPasswordLength?: number): Promise<void>;
|
|
24
|
+
}
|
|
@@ -29,10 +29,11 @@ export declare class TokenHelper {
|
|
|
29
29
|
* @param signingKeyName The signing key name.
|
|
30
30
|
* @param token The token to verify.
|
|
31
31
|
* @param requiredScopes The required scopes.
|
|
32
|
+
* @param verifyUser A function to verify the user identity and organization, which can be used to check if the user is still active or not.
|
|
32
33
|
* @returns The verified details.
|
|
33
34
|
* @throws UnauthorizedError if the token is missing, invalid or expired.
|
|
34
35
|
*/
|
|
35
|
-
static verify(vaultConnector: IVaultConnector, signingKeyName: string, token: string | undefined, requiredScopes?: string[]): Promise<{
|
|
36
|
+
static verify(vaultConnector: IVaultConnector, signingKeyName: string, token: string | undefined, requiredScopes?: string[], verifyUser?: (userIdentity: string, organizationIdentity: string) => Promise<string[]>): Promise<{
|
|
36
37
|
header: IJwtHeader;
|
|
37
38
|
payload: IJwtPayload;
|
|
38
39
|
}>;
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.24](https://github.com/twinfoundation/api/compare/api-auth-entity-storage-service-v0.0.3-next.23...api-auth-entity-storage-service-v0.0.3-next.24) (2026-04-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* remove auth service dependency on admin service ([4aeb211](https://github.com/twinfoundation/api/commit/4aeb211a5ffcf2eaea89a6841faea3ac3069ef89))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/api-auth-entity-storage-models bumped from 0.0.3-next.23 to 0.0.3-next.24
|
|
16
|
+
* @twin.org/api-core bumped from 0.0.3-next.23 to 0.0.3-next.24
|
|
17
|
+
* @twin.org/api-models bumped from 0.0.3-next.23 to 0.0.3-next.24
|
|
18
|
+
|
|
19
|
+
## [0.0.3-next.23](https://github.com/twinfoundation/api/compare/api-auth-entity-storage-service-v0.0.3-next.22...api-auth-entity-storage-service-v0.0.3-next.23) (2026-04-14)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* auth enhancements ([#93](https://github.com/twinfoundation/api/issues/93)) ([921a50c](https://github.com/twinfoundation/api/commit/921a50cd89d26e530a6be6174a5a803060fa0eb6))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @twin.org/api-auth-entity-storage-models bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
32
|
+
* @twin.org/api-core bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
33
|
+
* @twin.org/api-models bumped from 0.0.3-next.22 to 0.0.3-next.23
|
|
34
|
+
|
|
3
35
|
## [0.0.3-next.22](https://github.com/twinfoundation/api/compare/api-auth-entity-storage-service-v0.0.3-next.21...api-auth-entity-storage-service-v0.0.3-next.22) (2026-03-27)
|
|
4
36
|
|
|
5
37
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Class: AuthenticationAuditEntry
|
|
2
|
+
|
|
3
|
+
Class defining the storage for authentication audit entries.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
> **new AuthenticationAuditEntry**(): `AuthenticationAuditEntry`
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
`AuthenticationAuditEntry`
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
### id {#id}
|
|
18
|
+
|
|
19
|
+
> **id**: `string`
|
|
20
|
+
|
|
21
|
+
The unique identifier for the audit entry.
|
|
22
|
+
|
|
23
|
+
***
|
|
24
|
+
|
|
25
|
+
### dateCreated {#datecreated}
|
|
26
|
+
|
|
27
|
+
> **dateCreated**: `string`
|
|
28
|
+
|
|
29
|
+
The timestamp of the audit entry in ISO 8601 format.
|
|
30
|
+
|
|
31
|
+
***
|
|
32
|
+
|
|
33
|
+
### event {#event}
|
|
34
|
+
|
|
35
|
+
> **event**: `string`
|
|
36
|
+
|
|
37
|
+
The audit event that occurred.
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### actorId? {#actorid}
|
|
42
|
+
|
|
43
|
+
> `optional` **actorId?**: `string`
|
|
44
|
+
|
|
45
|
+
The actor identifier, could be e-mail, username, or other unique identifier.
|
|
46
|
+
|
|
47
|
+
***
|
|
48
|
+
|
|
49
|
+
### nodeId? {#nodeid}
|
|
50
|
+
|
|
51
|
+
> `optional` **nodeId?**: `string`
|
|
52
|
+
|
|
53
|
+
The node identifier associated with the audit entry, if applicable.
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### organizationId? {#organizationid}
|
|
58
|
+
|
|
59
|
+
> `optional` **organizationId?**: `string`
|
|
60
|
+
|
|
61
|
+
The organization identifier associated with the audit entry, if applicable.
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### tenantId? {#tenantid}
|
|
66
|
+
|
|
67
|
+
> `optional` **tenantId?**: `string`
|
|
68
|
+
|
|
69
|
+
The tenant identifier associated with the audit entry, if applicable.
|
|
70
|
+
|
|
71
|
+
***
|
|
72
|
+
|
|
73
|
+
### ipAddressHashes? {#ipaddresshashes}
|
|
74
|
+
|
|
75
|
+
> `optional` **ipAddressHashes?**: `string`[]
|
|
76
|
+
|
|
77
|
+
The hashed IP addresses of the client.
|
|
78
|
+
|
|
79
|
+
***
|
|
80
|
+
|
|
81
|
+
### userAgent? {#useragent}
|
|
82
|
+
|
|
83
|
+
> `optional` **userAgent?**: `string`
|
|
84
|
+
|
|
85
|
+
The user agent string of the client.
|
|
86
|
+
|
|
87
|
+
***
|
|
88
|
+
|
|
89
|
+
### correlationId? {#correlationid}
|
|
90
|
+
|
|
91
|
+
> `optional` **correlationId?**: `string`
|
|
92
|
+
|
|
93
|
+
The correlation ID for request tracing.
|
|
94
|
+
|
|
95
|
+
***
|
|
96
|
+
|
|
97
|
+
### data? {#data}
|
|
98
|
+
|
|
99
|
+
> `optional` **data?**: `unknown`
|
|
100
|
+
|
|
101
|
+
Additional data related to the audit entry, such as IP address, user agent, etc.
|