@3sixty/api-auth-entity-storage-service 0.0.0-stage → 0.20.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/es/entities/authenticationUser.js +61 -0
  4. package/dist/es/entities/authenticationUser.js.map +1 -0
  5. package/dist/es/entities/authenticationUserV0.js +69 -0
  6. package/dist/es/entities/authenticationUserV0.js.map +1 -0
  7. package/dist/es/index.js +21 -0
  8. package/dist/es/index.js.map +1 -0
  9. package/dist/es/models/IAuthHeaderProcessorConfig.js +4 -0
  10. package/dist/es/models/IAuthHeaderProcessorConfig.js.map +1 -0
  11. package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js +2 -0
  12. package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -0
  13. package/dist/es/models/IAuthTokenContext.js +4 -0
  14. package/dist/es/models/IAuthTokenContext.js.map +1 -0
  15. package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js +4 -0
  16. package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js.map +1 -0
  17. package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js +2 -0
  18. package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js.map +1 -0
  19. package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js +2 -0
  20. package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -0
  21. package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js +2 -0
  22. package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -0
  23. package/dist/es/processors/authHeaderProcessor.js +272 -0
  24. package/dist/es/processors/authHeaderProcessor.js.map +1 -0
  25. package/dist/es/restEntryPoints.js +20 -0
  26. package/dist/es/restEntryPoints.js.map +1 -0
  27. package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js +375 -0
  28. package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js.map +1 -0
  29. package/dist/es/routes/entityStorageAuthenticationRoutes.js +291 -0
  30. package/dist/es/routes/entityStorageAuthenticationRoutes.js.map +1 -0
  31. package/dist/es/schema.js +13 -0
  32. package/dist/es/schema.js.map +1 -0
  33. package/dist/es/services/entityStorageAuthenticationAdminService.js +324 -0
  34. package/dist/es/services/entityStorageAuthenticationAdminService.js.map +1 -0
  35. package/dist/es/services/entityStorageAuthenticationService.js +338 -0
  36. package/dist/es/services/entityStorageAuthenticationService.js.map +1 -0
  37. package/dist/es/utils/passwordHelper.js +60 -0
  38. package/dist/es/utils/passwordHelper.js.map +1 -0
  39. package/dist/es/utils/tokenHelper.js +121 -0
  40. package/dist/es/utils/tokenHelper.js.map +1 -0
  41. package/dist/types/entities/authenticationUser.d.ts +29 -0
  42. package/dist/types/entities/authenticationUserV0.d.ts +33 -0
  43. package/dist/types/index.d.ts +18 -0
  44. package/dist/types/models/IAuthHeaderProcessorConfig.d.ts +38 -0
  45. package/dist/types/models/IAuthHeaderProcessorConstructorOptions.d.ts +25 -0
  46. package/dist/types/models/IAuthTokenContext.d.ts +30 -0
  47. package/dist/types/models/IEntityStorageAuthenticationAdminServiceConfig.d.ts +25 -0
  48. package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +25 -0
  49. package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +41 -0
  50. package/dist/types/models/IEntityStorageAuthenticationServiceConstructorOptions.d.ts +35 -0
  51. package/dist/types/processors/authHeaderProcessor.d.ts +57 -0
  52. package/dist/types/restEntryPoints.d.ts +5 -0
  53. package/dist/types/routes/entityStorageAuthenticationAdminRoutes.d.ts +62 -0
  54. package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +53 -0
  55. package/dist/types/schema.d.ts +4 -0
  56. package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +69 -0
  57. package/dist/types/services/entityStorageAuthenticationService.d.ts +70 -0
  58. package/dist/types/utils/passwordHelper.d.ts +27 -0
  59. package/dist/types/utils/tokenHelper.d.ts +51 -0
  60. package/docs/changelog.md +19 -0
  61. package/docs/examples.md +94 -0
  62. package/docs/open-api/spec.json +1344 -0
  63. package/docs/reference/classes/AuthHeaderProcessor.md +197 -0
  64. package/docs/reference/classes/AuthenticationUser.md +61 -0
  65. package/docs/reference/classes/AuthenticationUserV0.md +69 -0
  66. package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +237 -0
  67. package/docs/reference/classes/EntityStorageAuthenticationService.md +239 -0
  68. package/docs/reference/classes/PasswordHelper.md +74 -0
  69. package/docs/reference/classes/TokenHelper.md +163 -0
  70. package/docs/reference/functions/authenticationAdminCreateUser.md +37 -0
  71. package/docs/reference/functions/authenticationAdminGetUser.md +31 -0
  72. package/docs/reference/functions/authenticationAdminGetUserByIdentity.md +31 -0
  73. package/docs/reference/functions/authenticationAdminRemoveUser.md +31 -0
  74. package/docs/reference/functions/authenticationAdminUpdateUser.md +31 -0
  75. package/docs/reference/functions/authenticationAdminUpdateUserPassword.md +31 -0
  76. package/docs/reference/functions/authenticationLogin.md +31 -0
  77. package/docs/reference/functions/authenticationLogout.md +31 -0
  78. package/docs/reference/functions/authenticationPasswordPolicy.md +31 -0
  79. package/docs/reference/functions/authenticationRefreshToken.md +31 -0
  80. package/docs/reference/functions/authenticationUpdatePassword.md +31 -0
  81. package/docs/reference/functions/generateRestRoutesAuthentication.md +25 -0
  82. package/docs/reference/functions/generateRestRoutesAuthenticationAdmin.md +25 -0
  83. package/docs/reference/functions/initSchema.md +9 -0
  84. package/docs/reference/index.md +44 -0
  85. package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +85 -0
  86. package/docs/reference/interfaces/IAuthHeaderProcessorConstructorOptions.md +53 -0
  87. package/docs/reference/interfaces/IAuthTokenContext.md +52 -0
  88. package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +59 -0
  89. package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +53 -0
  90. package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +101 -0
  91. package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConstructorOptions.md +81 -0
  92. package/docs/reference/variables/restEntryPoints.md +5 -0
  93. package/docs/reference/variables/tagsAuthentication.md +5 -0
  94. package/docs/reference/variables/tagsAuthenticationAdmin.md +5 -0
  95. package/locales/en.json +37 -0
  96. package/package.json +63 -5
@@ -0,0 +1,121 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { Coerce, Is, UnauthorizedError } from "@3sixty/core";
4
+ import { VaultConnectorHelper } from "@3sixty/vault-models";
5
+ import { CookieHelper, HeaderHelper, HeaderTypes, Jwt } from "@3sixty/web";
6
+ /**
7
+ * Helper class for token operations.
8
+ */
9
+ export class TokenHelper {
10
+ /**
11
+ * Runtime name for the class.
12
+ */
13
+ static CLASS_NAME = "TokenHelper";
14
+ /**
15
+ * Create a new token.
16
+ * @param vaultConnector The vault connector.
17
+ * @param nodeId The node identifier, embedded as the JWT issuer claim.
18
+ * @param signingKeyName The signing key name, embedded as the JWT key identifier.
19
+ * @param userIdentity The subject for the token.
20
+ * @param organizationIdentity The organization for the token.
21
+ * @param tenantId The tenant id for the token.
22
+ * @param ttlMinutes The time to live for the token in minutes.
23
+ * @param passwordVersion The user's current password version counter, embedded in the token so that a password change invalidates existing tokens.
24
+ * @returns The new token and its expiry date.
25
+ */
26
+ static async createToken(vaultConnector, nodeId, signingKeyName, userIdentity, organizationIdentity, tenantId, ttlMinutes, passwordVersion) {
27
+ const nowSeconds = Math.trunc(Date.now() / 1000);
28
+ const ttlSeconds = ttlMinutes * 60;
29
+ const vaultKeyName = `${nodeId}/${signingKeyName}`;
30
+ const jwt = await Jwt.encodeWithSigner({ alg: "EdDSA", kid: signingKeyName }, {
31
+ iss: nodeId,
32
+ sub: userIdentity,
33
+ org: organizationIdentity,
34
+ tid: tenantId,
35
+ exp: nowSeconds + ttlSeconds,
36
+ pver: passwordVersion
37
+ }, async (header, payload) => VaultConnectorHelper.jwtSigner(vaultConnector, vaultKeyName, header, payload));
38
+ return {
39
+ token: jwt,
40
+ expiry: (nowSeconds + ttlSeconds) * 1000
41
+ };
42
+ }
43
+ /**
44
+ * Verify the token.
45
+ * @param vaultConnector The vault connector.
46
+ * @param nodeId The node identifier, expected to match the JWT issuer claim.
47
+ * @param signingKeyName The signing key name, expected to match the JWT key identifier.
48
+ * @param token The token to verify.
49
+ * @param verifyUser A function to verify the user identity and organization. The password version counter embedded in the token (pver claim) is passed so callers can detect if the password has changed since the token was issued.
50
+ * @returns The verified details.
51
+ * @throws UnauthorizedError if the token is missing, invalid or expired.
52
+ */
53
+ static async verify(vaultConnector, nodeId, signingKeyName, token, verifyUser) {
54
+ if (!Is.stringValue(token)) {
55
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "missing");
56
+ }
57
+ const vaultKeyName = `${nodeId}/${signingKeyName}`;
58
+ const decoded = await Jwt.verifyWithVerifier(token, async (t) => VaultConnectorHelper.jwtVerifier(vaultConnector, vaultKeyName, t));
59
+ // If some of the header/payload data is not properly populated then it is unauthorized.
60
+ if (decoded.header.kid !== signingKeyName) {
61
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "headerKeyIdMismatch");
62
+ }
63
+ else if (decoded.payload.iss !== nodeId) {
64
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "payloadIssuerMismatch");
65
+ }
66
+ else if (!Is.stringValue(decoded.payload.sub)) {
67
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "payloadMissingSubject");
68
+ }
69
+ else if (!Is.stringValue(decoded.payload.org)) {
70
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "payloadMissingOrganization");
71
+ }
72
+ else if (!Is.empty(decoded.payload?.exp) &&
73
+ decoded.payload.exp < Math.trunc(Date.now() / 1000)) {
74
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "expired");
75
+ }
76
+ if (Is.function(verifyUser)) {
77
+ const tid = Coerce.string(decoded.payload.tid);
78
+ const userVerified = await verifyUser(decoded.payload.sub, decoded.payload.org, tid, Coerce.integer(decoded.payload.pver));
79
+ if (!userVerified.includes("user")) {
80
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "userNotVerified");
81
+ }
82
+ else if (!userVerified.includes("organization")) {
83
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "organizationNotVerified");
84
+ }
85
+ else if (Is.stringValue(tid) && !userVerified.includes("tenant")) {
86
+ throw new UnauthorizedError(TokenHelper.CLASS_NAME, "tenantNotVerified");
87
+ }
88
+ }
89
+ return {
90
+ header: decoded.header,
91
+ payload: decoded.payload
92
+ };
93
+ }
94
+ /**
95
+ * Extract the auth token from the headers, either from the authorization header or the cookie header.
96
+ * @param headers The headers to extract the token from.
97
+ * @param cookieName The name of the cookie to extract the token from.
98
+ * @returns The token if found.
99
+ */
100
+ static extractTokenFromHeaders(headers, cookieName) {
101
+ const authHeader = headers?.[HeaderTypes.Authorization];
102
+ const cookiesHeader = headers?.[HeaderTypes.Cookie];
103
+ const bearerToken = HeaderHelper.extractBearer(authHeader);
104
+ if (Is.stringValue(bearerToken)) {
105
+ return {
106
+ token: bearerToken,
107
+ location: "authorization"
108
+ };
109
+ }
110
+ else if (Is.notEmpty(cookiesHeader) && Is.stringValue(cookieName)) {
111
+ const value = CookieHelper.getCookieFromHeaders(cookiesHeader, cookieName);
112
+ if (Is.stringValue(value)) {
113
+ return {
114
+ token: value,
115
+ location: "cookie"
116
+ };
117
+ }
118
+ }
119
+ }
120
+ }
121
+ //# sourceMappingURL=tokenHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenHelper.js","sources":["../../../src/utils/tokenHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,E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EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QACxD,MAAM,aAAa,GAAG,OAAO,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEpD,MAAM,WAAW,GAAG,YAAY,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;YACjC,OAAO;gBACN,KAAK,EAAE,WAAW;gBAClB,QAAQ,EAAE,eAAe;aACzB,CAAC;QACH,CAAC;aAAM,IAAI,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;YACrE,MAAM,KAAK,GAAG,YAAY,CAAC,oBAAoB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;YAC3E,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,OAAO;oBACN,KAAK,EAAE,KAAK;oBACZ,QAAQ,EAAE,QAAQ;iBAClB,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, Is, UnauthorizedError } from \"@3sixty/core\";\n\nimport { type IVaultConnector, VaultConnectorHelper } from \"@3sixty/vault-models\";\nimport {\n\tCookieHelper,\n\tHeaderHelper,\n\tHeaderTypes,\n\ttype IHttpHeaders,\n\ttype IJwtHeader,\n\ttype IJwtPayload,\n\tJwt\n} from \"@3sixty/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 = \"TokenHelper\";\n\n\t/**\n\t * Create a new token.\n\t * @param vaultConnector The vault connector.\n\t * @param nodeId The node identifier, embedded as the JWT issuer claim.\n\t * @param signingKeyName The signing key name, embedded as the JWT key identifier.\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 passwordVersion The user's current password version counter, embedded in the token so that a password change invalidates existing tokens.\n\t * @returns The new token and its expiry date.\n\t */\n\tpublic static async createToken(\n\t\tvaultConnector: IVaultConnector,\n\t\tnodeId: string,\n\t\tsigningKeyName: string,\n\t\tuserIdentity: string,\n\t\torganizationIdentity: string | undefined,\n\t\ttenantId: string | undefined,\n\t\tttlMinutes: number,\n\t\tpasswordVersion?: number\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\t\tconst vaultKeyName = `${nodeId}/${signingKeyName}`;\n\n\t\tconst jwt = await Jwt.encodeWithSigner(\n\t\t\t{ alg: \"EdDSA\", kid: signingKeyName },\n\t\t\t{\n\t\t\t\tiss: nodeId,\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\tpver: passwordVersion\n\t\t\t},\n\t\t\tasync (header, payload) =>\n\t\t\t\tVaultConnectorHelper.jwtSigner(vaultConnector, vaultKeyName, 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 nodeId The node identifier, expected to match the JWT issuer claim.\n\t * @param signingKeyName The signing key name, expected to match the JWT key identifier.\n\t * @param token The token to verify.\n\t * @param verifyUser A function to verify the user identity and organization. The password version counter embedded in the token (pver claim) is passed so callers can detect if the password has changed since the token was issued.\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\tnodeId: string,\n\t\tsigningKeyName: string,\n\t\ttoken: string | undefined,\n\t\tverifyUser?: (\n\t\t\tsub: string,\n\t\t\torg: string,\n\t\t\ttid: string | undefined,\n\t\t\tpasswordVersion: number | undefined\n\t\t) => 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 vaultKeyName = `${nodeId}/${signingKeyName}`;\n\t\tconst decoded = await Jwt.verifyWithVerifier(token, async t =>\n\t\t\tVaultConnectorHelper.jwtVerifier(vaultConnector, vaultKeyName, 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 (decoded.header.kid !== signingKeyName) {\n\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"headerKeyIdMismatch\");\n\t\t} else if (decoded.payload.iss !== nodeId) {\n\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"payloadIssuerMismatch\");\n\t\t} else if (!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 tid = Coerce.string(decoded.payload.tid);\n\t\t\tconst userVerified = await verifyUser(\n\t\t\t\tdecoded.payload.sub,\n\t\t\t\tdecoded.payload.org,\n\t\t\t\ttid,\n\t\t\t\tCoerce.integer(decoded.payload.pver)\n\t\t\t);\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} else if (Is.stringValue(tid) && !userVerified.includes(\"tenant\")) {\n\t\t\t\tthrow new UnauthorizedError(TokenHelper.CLASS_NAME, \"tenantNotVerified\");\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,29 @@
1
+ /**
2
+ * Class defining the storage for user login credentials.
3
+ */
4
+ export declare class AuthenticationUser {
5
+ /**
6
+ * The user e-mail address.
7
+ */
8
+ email: string;
9
+ /**
10
+ * The encrypted password for the user.
11
+ */
12
+ password: string;
13
+ /**
14
+ * The salt for the password.
15
+ */
16
+ salt: string;
17
+ /**
18
+ * The user identity.
19
+ */
20
+ identity: string;
21
+ /**
22
+ * The users organization.
23
+ */
24
+ organization: string;
25
+ /**
26
+ * The password version counter, incremented on every password change to invalidate existing tokens.
27
+ */
28
+ passwordVersion?: number;
29
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Class defining the storage for user login credentials.
3
+ */
4
+ export declare class AuthenticationUserV0 {
5
+ /**
6
+ * The user e-mail address.
7
+ */
8
+ email: string;
9
+ /**
10
+ * The encrypted password for the user.
11
+ */
12
+ password: string;
13
+ /**
14
+ * The salt for the password.
15
+ */
16
+ salt: string;
17
+ /**
18
+ * The user identity.
19
+ */
20
+ identity: string;
21
+ /**
22
+ * The users organization.
23
+ */
24
+ organization: string;
25
+ /**
26
+ * The scope assigned to the user, comma separated.
27
+ */
28
+ scope: string;
29
+ /**
30
+ * The password version counter, incremented on every password change to invalidate existing tokens.
31
+ */
32
+ passwordVersion?: number;
33
+ }
@@ -0,0 +1,18 @@
1
+ export * from "./entities/authenticationUser.js";
2
+ export * from "./entities/authenticationUserV0.js";
3
+ export * from "./models/IAuthHeaderProcessorConfig.js";
4
+ export * from "./models/IAuthHeaderProcessorConstructorOptions.js";
5
+ export * from "./models/IAuthTokenContext.js";
6
+ export * from "./models/IEntityStorageAuthenticationAdminServiceConfig.js";
7
+ export * from "./models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js";
8
+ export * from "./models/IEntityStorageAuthenticationServiceConfig.js";
9
+ export * from "./models/IEntityStorageAuthenticationServiceConstructorOptions.js";
10
+ export * from "./processors/authHeaderProcessor.js";
11
+ export * from "./restEntryPoints.js";
12
+ export * from "./routes/entityStorageAuthenticationAdminRoutes.js";
13
+ export * from "./routes/entityStorageAuthenticationRoutes.js";
14
+ export * from "./schema.js";
15
+ export * from "./services/entityStorageAuthenticationAdminService.js";
16
+ export * from "./services/entityStorageAuthenticationService.js";
17
+ export * from "./utils/tokenHelper.js";
18
+ export * from "./utils/passwordHelper.js";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Configuration for the authentication header processor
3
+ */
4
+ export interface IAuthHeaderProcessorConfig {
5
+ /**
6
+ * The name of the key to retrieve from the vault for signing JWT.
7
+ * @default auth-signing
8
+ */
9
+ signingKeyName?: string;
10
+ /**
11
+ * The name of the cookie to use for the token.
12
+ * @default access_token
13
+ */
14
+ cookieName?: string;
15
+ /**
16
+ * Include the stack with errors.
17
+ */
18
+ includeErrorStack?: boolean;
19
+ /**
20
+ * The time in milliseconds a verified token is kept in the in-memory cache, counted from when it
21
+ * was verified and not extended by use, set to 0 to disable caching. A hit skips the vault
22
+ * signature check, the tenant lookup and the user lookup, so this is also the longest a password
23
+ * change, a user removal or a signing key rotation can go unnoticed. An entry never outlives the
24
+ * expiry claim of its own token either.
25
+ * @default 30000
26
+ */
27
+ tokenCacheTtlMs?: number;
28
+ /**
29
+ * The maximum number of verified tokens to hold in the in-memory cache.
30
+ * @default undefined (LfuCache default)
31
+ */
32
+ tokenCacheCapacity?: number;
33
+ /**
34
+ * Maximum time in milliseconds to wait for the token cache mutex during a cache population.
35
+ * @default undefined (LfuCache default)
36
+ */
37
+ tokenCacheMutexTimeoutMs?: number;
38
+ }
@@ -0,0 +1,25 @@
1
+ import type { IAuthHeaderProcessorConfig } from "./IAuthHeaderProcessorConfig.js";
2
+ /**
3
+ * Options for the AuthHeaderProcessor constructor.
4
+ */
5
+ export interface IAuthHeaderProcessorConstructorOptions {
6
+ /**
7
+ * The entity storage for users.
8
+ * @default authentication-user
9
+ */
10
+ userEntityStorageType?: string;
11
+ /**
12
+ * The vault for the private keys.
13
+ * @default vault
14
+ */
15
+ vaultConnectorType?: string;
16
+ /**
17
+ * The component to retrieve tenant information.
18
+ * @default tenant-admin
19
+ */
20
+ tenantAdminComponentType?: string;
21
+ /**
22
+ * The configuration for the processor.
23
+ */
24
+ config?: IAuthHeaderProcessorConfig;
25
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The context resolved from an access token, everything a request needs that does not depend on
3
+ * the route being called.
4
+ */
5
+ export interface IAuthTokenContext {
6
+ /**
7
+ * The tenant id from the token, if it carried one.
8
+ */
9
+ tenantId?: string;
10
+ /**
11
+ * The organization id of the tenant the token belongs to.
12
+ */
13
+ tenantOrganizationId?: string;
14
+ /**
15
+ * The public origin of the tenant the token belongs to.
16
+ */
17
+ tenantPublicOrigin?: string;
18
+ /**
19
+ * The identity of the verified user.
20
+ */
21
+ userIdentity?: string;
22
+ /**
23
+ * The organization of the verified user.
24
+ */
25
+ userOrganization?: string;
26
+ /**
27
+ * The expiry of the token in milliseconds since the epoch, if it carried one.
28
+ */
29
+ expires?: number;
30
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Configuration for the entity storage authentication admin service.
3
+ */
4
+ export interface IEntityStorageAuthenticationAdminServiceConfig {
5
+ /**
6
+ * The minimum password length.
7
+ * @default 15
8
+ */
9
+ minPasswordLength?: number;
10
+ /**
11
+ * The maximum password length.
12
+ * @default 128
13
+ */
14
+ maxPasswordLength?: number;
15
+ /**
16
+ * The role that grants escalated privilege, only callers holding it can modify accounts that hold it.
17
+ * @default global-admin
18
+ */
19
+ escalatedPrivilegeRole?: string;
20
+ /**
21
+ * The authorization model ID used to look up roles.
22
+ * @default system
23
+ */
24
+ authorizationModelId?: string;
25
+ }
@@ -0,0 +1,25 @@
1
+ import type { IEntityStorageAuthenticationAdminServiceConfig } from "./IEntityStorageAuthenticationAdminServiceConfig.js";
2
+ /**
3
+ * Options for the EntityStorageAuthenticationAdminService constructor.
4
+ */
5
+ export interface IEntityStorageAuthenticationAdminServiceConstructorOptions {
6
+ /**
7
+ * The entity storage for the users.
8
+ * @default authentication-user
9
+ */
10
+ userEntityStorageType?: string;
11
+ /**
12
+ * The audit component.
13
+ * @default authentication-audit
14
+ */
15
+ authenticationAuditServiceType?: string;
16
+ /**
17
+ * The authorization component used to guard accounts with escalated privilege.
18
+ * @default authorization
19
+ */
20
+ authorizationComponentType?: string;
21
+ /**
22
+ * The configuration for the authentication.
23
+ */
24
+ config?: IEntityStorageAuthenticationAdminServiceConfig;
25
+ }
@@ -0,0 +1,41 @@
1
+ import type { IAuthenticationRateActionConfig } from "@3sixty/api-auth-models";
2
+ /**
3
+ * Configuration for the entity storage authentication service.
4
+ */
5
+ export interface IEntityStorageAuthenticationServiceConfig {
6
+ /**
7
+ * The name of the key to retrieve from the vault for signing JWT.
8
+ * @default auth-signing
9
+ */
10
+ signingKeyName?: string;
11
+ /**
12
+ * The default time to live for the JWT.
13
+ * @default 60
14
+ */
15
+ defaultTtlMinutes?: number;
16
+ /**
17
+ * The minimum password length for new password validation.
18
+ * @default 15
19
+ */
20
+ minPasswordLength?: number;
21
+ /**
22
+ * The maximum password length for new password validation.
23
+ * @default 128
24
+ */
25
+ maxPasswordLength?: number;
26
+ /**
27
+ * Optional override for login failure rate limit.
28
+ * @default { maxAttempts: 5, windowMinutes: 15 }
29
+ */
30
+ loginRateLimit?: IAuthenticationRateActionConfig;
31
+ /**
32
+ * Optional override for password change rate limit.
33
+ * @default { maxAttempts: 5, windowMinutes: 15 }
34
+ */
35
+ passwordChangeRateLimit?: IAuthenticationRateActionConfig;
36
+ /**
37
+ * Optional override for token refresh rate limit.
38
+ * @default { maxAttempts: 30, windowMinutes: 60 }
39
+ */
40
+ tokenRefreshRateLimit?: IAuthenticationRateActionConfig;
41
+ }
@@ -0,0 +1,35 @@
1
+ import type { IEntityStorageAuthenticationServiceConfig } from "./IEntityStorageAuthenticationServiceConfig.js";
2
+ /**
3
+ * Options for the EntityStorageAuthenticationService constructor.
4
+ */
5
+ export interface IEntityStorageAuthenticationServiceConstructorOptions {
6
+ /**
7
+ * The entity storage for the users.
8
+ * @default authentication-user
9
+ */
10
+ userEntityStorageType?: string;
11
+ /**
12
+ * The vault for the private keys.
13
+ * @default vault
14
+ */
15
+ vaultConnectorType?: string;
16
+ /**
17
+ * The audit service.
18
+ * @default authentication-audit
19
+ */
20
+ authenticationAuditServiceType?: string;
21
+ /**
22
+ * The rate service.
23
+ * @default authentication-rate
24
+ */
25
+ authenticationRateServiceType?: string;
26
+ /**
27
+ * The component to retrieve tenant information.
28
+ * @default tenant-admin
29
+ */
30
+ tenantAdminComponentType?: string;
31
+ /**
32
+ * The configuration for the authentication.
33
+ */
34
+ config?: IEntityStorageAuthenticationServiceConfig;
35
+ }
@@ -0,0 +1,57 @@
1
+ import { type IBaseRoute, type IBaseRouteProcessor, type IHttpResponse, type IHttpServerRequest } from "@3sixty/api-models";
2
+ import { type IContextIds } from "@3sixty/context";
3
+ import type { IAuthHeaderProcessorConstructorOptions } from "../models/IAuthHeaderProcessorConstructorOptions.js";
4
+ /**
5
+ * Handle a JWT token in the authorization header or cookies and validate it to populate request context identity.
6
+ */
7
+ export declare class AuthHeaderProcessor implements IBaseRouteProcessor {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of AuthHeaderProcessor.
14
+ * @param options Options for the processor.
15
+ */
16
+ constructor(options?: IAuthHeaderProcessorConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * The service needs to be started when the application is initialized.
24
+ * @param nodeLoggingComponentType The node logging component type.
25
+ * @returns A promise that resolves when the node identity and organization ID have been cached.
26
+ */
27
+ start(nodeLoggingComponentType?: string): Promise<void>;
28
+ /**
29
+ * Stop the processor and release the token cache.
30
+ * @returns A promise that resolves when the processor has stopped.
31
+ */
32
+ stop(): Promise<void>;
33
+ /**
34
+ * Pre process the REST request for the specified route.
35
+ * @param request The incoming request.
36
+ * @param response The outgoing response.
37
+ * @param route The route to process.
38
+ * @param contextIds The context IDs of the request.
39
+ * @param processorState The state handed through the processors.
40
+ * @returns A promise that resolves when the JWT has been verified and the context populated, or an error response set.
41
+ */
42
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
43
+ [id: string]: unknown;
44
+ }): Promise<void>;
45
+ /**
46
+ * Post process the REST request for the specified route.
47
+ * @param request The incoming request.
48
+ * @param response The outgoing response.
49
+ * @param route The route to process.
50
+ * @param contextIds The context IDs of the request.
51
+ * @param processorState The state handed through the processors.
52
+ * @returns A promise that resolves when the Set-Cookie header has been applied to the response if required.
53
+ */
54
+ post(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
55
+ [id: string]: unknown;
56
+ }): Promise<void>;
57
+ }
@@ -0,0 +1,5 @@
1
+ import type { IRestRouteEntryPoint } from "@3sixty/api-models";
2
+ /**
3
+ * REST entry points for the authentication and authentication admin services.
4
+ */
5
+ export declare const restEntryPoints: IRestRouteEntryPoint[];
@@ -0,0 +1,62 @@
1
+ import type { IAdminUserCreateRequest, IAdminUserGetByIdentityRequest, IAdminUserGetRequest, IAdminUserGetResponse, IAdminUserRemoveRequest, IAdminUserUpdatePasswordRequest, IAdminUserUpdateRequest } from "@3sixty/api-auth-entity-storage-models";
2
+ import { type ICreatedResponse, type IHttpRequestContext, type INoContentResponse, type IRestRoute, type ITag } from "@3sixty/api-models";
3
+ /**
4
+ * The tag to associate with the routes.
5
+ */
6
+ export declare const tagsAuthenticationAdmin: ITag[];
7
+ /**
8
+ * The REST routes for authentication admin.
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 generateRestRoutesAuthenticationAdmin(baseRouteName: string, componentName: string): IRestRoute[];
14
+ /**
15
+ * Create a new user.
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
+ * @param baseRouteName The base route name to use for the location header.
20
+ * @returns The response object with additional http response properties.
21
+ */
22
+ export declare function authenticationAdminCreateUser(httpRequestContext: IHttpRequestContext, componentName: string, request: IAdminUserCreateRequest, baseRouteName: string): Promise<ICreatedResponse>;
23
+ /**
24
+ * Update an existing user.
25
+ * @param httpRequestContext The request context for the API.
26
+ * @param componentName The name of the component to use in the routes.
27
+ * @param request The request.
28
+ * @returns The response object with additional http response properties.
29
+ */
30
+ export declare function authenticationAdminUpdateUser(httpRequestContext: IHttpRequestContext, componentName: string, request: IAdminUserUpdateRequest): Promise<INoContentResponse>;
31
+ /**
32
+ * Update an existing user password.
33
+ * @param httpRequestContext The request context for the API.
34
+ * @param componentName The name of the component to use in the routes.
35
+ * @param request The request.
36
+ * @returns The response object with additional http response properties.
37
+ */
38
+ export declare function authenticationAdminUpdateUserPassword(httpRequestContext: IHttpRequestContext, componentName: string, request: IAdminUserUpdatePasswordRequest): Promise<INoContentResponse>;
39
+ /**
40
+ * Get an existing user.
41
+ * @param httpRequestContext The request context for the API.
42
+ * @param componentName The name of the component to use in the routes.
43
+ * @param request The request.
44
+ * @returns The response object with additional http response properties.
45
+ */
46
+ export declare function authenticationAdminGetUser(httpRequestContext: IHttpRequestContext, componentName: string, request: IAdminUserGetRequest): Promise<IAdminUserGetResponse>;
47
+ /**
48
+ * Get an existing user by identity.
49
+ * @param httpRequestContext The request context for the API.
50
+ * @param componentName The name of the component to use in the routes.
51
+ * @param request The request.
52
+ * @returns The response object with additional http response properties.
53
+ */
54
+ export declare function authenticationAdminGetUserByIdentity(httpRequestContext: IHttpRequestContext, componentName: string, request: IAdminUserGetByIdentityRequest): Promise<IAdminUserGetResponse>;
55
+ /**
56
+ * Remove an existing user.
57
+ * @param httpRequestContext The request context for the API.
58
+ * @param componentName The name of the component to use in the routes.
59
+ * @param request The request.
60
+ * @returns The response object with additional http response properties.
61
+ */
62
+ export declare function authenticationAdminRemoveUser(httpRequestContext: IHttpRequestContext, componentName: string, request: IAdminUserRemoveRequest): Promise<INoContentResponse>;
@@ -0,0 +1,53 @@
1
+ import type { ILoginRequest, ILoginResponse, ILogoutRequest, IPasswordPolicyResponse, IRefreshTokenRequest, IRefreshTokenResponse, IUpdatePasswordRequest } from "@3sixty/api-auth-entity-storage-models";
2
+ import type { IHttpRequestContext, INoContentRequest, INoContentResponse, IRestRoute, IRestRouteResponseOptions, ITag } from "@3sixty/api-models";
3
+ /**
4
+ * The tag to associate with the routes.
5
+ */
6
+ export declare const tagsAuthentication: ITag[];
7
+ /**
8
+ * The REST routes for authentication.
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 generateRestRoutesAuthentication(baseRouteName: string, componentName: string): IRestRoute[];
14
+ /**
15
+ * Login to the server.
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 authenticationLogin(httpRequestContext: IHttpRequestContext, componentName: string, request: ILoginRequest): Promise<ILoginResponse & IRestRouteResponseOptions>;
22
+ /**
23
+ * Logout from the server.
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 authenticationLogout(httpRequestContext: IHttpRequestContext, componentName: string, request: ILogoutRequest): Promise<INoContentResponse & IRestRouteResponseOptions>;
30
+ /**
31
+ * Refresh the login token.
32
+ * @param httpRequestContext The request context for the API.
33
+ * @param componentName The name of the component to use in the routes.
34
+ * @param request The request.
35
+ * @returns The response object with additional http response properties.
36
+ */
37
+ export declare function authenticationRefreshToken(httpRequestContext: IHttpRequestContext, componentName: string, request: IRefreshTokenRequest): Promise<IRefreshTokenResponse & IRestRouteResponseOptions>;
38
+ /**
39
+ * Update the user's password.
40
+ * @param httpRequestContext The request context for the API.
41
+ * @param componentName The name of the component to use in the routes.
42
+ * @param request The request.
43
+ * @returns The response object with additional http response properties.
44
+ */
45
+ export declare function authenticationUpdatePassword(httpRequestContext: IHttpRequestContext, componentName: string, request: IUpdatePasswordRequest): Promise<INoContentResponse>;
46
+ /**
47
+ * Get the password policy.
48
+ * @param httpRequestContext The request context for the API.
49
+ * @param componentName The name of the component to use in the routes.
50
+ * @param request The request.
51
+ * @returns The response object with additional http response properties.
52
+ */
53
+ export declare function authenticationPasswordPolicy(httpRequestContext: IHttpRequestContext, componentName: string, request: INoContentRequest): Promise<IPasswordPolicyResponse & IRestRouteResponseOptions>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Initialize the schema for the authentication service.
3
+ */
4
+ export declare function initSchema(): void;