@degenerate/endpoints 0.0.3 → 0.0.4

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 (212) hide show
  1. package/dist/endpoints/src/cors/authority/audience/get-set-audiences.d.ts +60 -0
  2. package/dist/endpoints/src/cors/authority/audience/get-set-audiences.d.ts.map +1 -0
  3. package/dist/endpoints/src/cors/authority/audience/get-set-audiences.js +90 -0
  4. package/dist/endpoints/src/cors/authority/jwt/validate-jwt-authorities.d.ts +16 -0
  5. package/dist/endpoints/src/cors/authority/jwt/validate-jwt-authorities.d.ts.map +1 -0
  6. package/dist/endpoints/src/cors/authority/jwt/validate-jwt-authorities.js +34 -0
  7. package/dist/endpoints/src/cors/endpoints/authorities/validate-authorities-transaction.d.ts +30 -0
  8. package/dist/endpoints/src/cors/endpoints/authorities/validate-authorities-transaction.d.ts.map +1 -0
  9. package/dist/endpoints/src/cors/endpoints/authorities/validate-authorities-transaction.js +155 -0
  10. package/dist/endpoints/src/cors/endpoints/helpers/validate-request-body.d.ts +11 -0
  11. package/dist/endpoints/src/cors/endpoints/helpers/validate-request-body.d.ts.map +1 -0
  12. package/dist/endpoints/src/cors/endpoints/helpers/validate-request-body.js +32 -0
  13. package/dist/{cors → endpoints/src/cors}/errors/all-error-handler.d.ts +2 -2
  14. package/dist/endpoints/src/cors/errors/all-error-handler.d.ts.map +1 -0
  15. package/dist/{cors → endpoints/src/cors}/errors/all-error-handler.js +1 -0
  16. package/dist/endpoints/src/cors/errors/bad-request-handler.d.ts +12 -0
  17. package/dist/endpoints/src/cors/errors/bad-request-handler.d.ts.map +1 -0
  18. package/dist/{cors → endpoints/src/cors}/errors/bad-request-handler.js +1 -0
  19. package/dist/endpoints/src/cors/errors/unauthorized-handler.d.ts +12 -0
  20. package/dist/endpoints/src/cors/errors/unauthorized-handler.d.ts.map +1 -0
  21. package/dist/{cors → endpoints/src/cors}/errors/unauthorized-handler.js +1 -0
  22. package/dist/endpoints/src/cors/index.d.ts +9 -0
  23. package/dist/endpoints/src/cors/index.d.ts.map +1 -0
  24. package/dist/{cors → endpoints/src/cors}/index.js +7 -0
  25. package/dist/endpoints/src/cors/routes/authorities.routes.d.ts +2 -0
  26. package/dist/endpoints/src/cors/routes/authorities.routes.d.ts.map +1 -0
  27. package/dist/endpoints/src/cors/routes/authorities.routes.js +69 -0
  28. package/dist/endpoints/src/cors/routes/events.routes.d.ts +2 -0
  29. package/dist/endpoints/src/cors/routes/events.routes.d.ts.map +1 -0
  30. package/dist/endpoints/src/cors/routes/events.routes.js +56 -0
  31. package/dist/endpoints/src/cors/routes/functions.routes.d.ts +2 -0
  32. package/dist/endpoints/src/cors/routes/functions.routes.d.ts.map +1 -0
  33. package/dist/endpoints/src/cors/routes/functions.routes.js +56 -0
  34. package/dist/endpoints/src/cors/routes/rules.routes.d.ts +2 -0
  35. package/dist/endpoints/src/cors/routes/rules.routes.d.ts.map +1 -0
  36. package/dist/endpoints/src/cors/routes/rules.routes.js +56 -0
  37. package/dist/endpoints/src/cors/routes/share-data.routes.d.ts +2 -0
  38. package/dist/endpoints/src/cors/routes/share-data.routes.d.ts.map +1 -0
  39. package/dist/endpoints/src/cors/routes/share-data.routes.js +56 -0
  40. package/dist/endpoints/src/examples/express-server/app.d.ts +3 -0
  41. package/dist/endpoints/src/examples/express-server/app.d.ts.map +1 -0
  42. package/dist/endpoints/src/examples/express-server/app.js +29 -0
  43. package/dist/endpoints/src/examples/express-server/server.d.ts +2 -0
  44. package/dist/endpoints/src/examples/express-server/server.d.ts.map +1 -0
  45. package/dist/endpoints/src/examples/express-server/server.js +9 -0
  46. package/dist/{index.d.ts.map → endpoints/src/index.d.ts.map} +1 -1
  47. package/dist/generic/src/_settings/authorization-settings.d.ts +17 -0
  48. package/dist/generic/src/_settings/authorization-settings.d.ts.map +1 -0
  49. package/dist/generic/src/_settings/authorization-settings.js +20 -0
  50. package/dist/generic/src/authorization/index.d.ts +24 -0
  51. package/dist/generic/src/authorization/index.d.ts.map +1 -0
  52. package/dist/generic/src/authorization/index.js +61 -0
  53. package/dist/generic/src/authorization/jwt/keys/create-public-key-pem.d.ts +9 -0
  54. package/dist/generic/src/authorization/jwt/keys/create-public-key-pem.d.ts.map +1 -0
  55. package/dist/generic/src/authorization/jwt/keys/create-public-key-pem.js +25 -0
  56. package/dist/generic/src/authorization/jwt/keys/create-secret-key-pem.d.ts +9 -0
  57. package/dist/generic/src/authorization/jwt/keys/create-secret-key-pem.d.ts.map +1 -0
  58. package/dist/generic/src/authorization/jwt/keys/create-secret-key-pem.js +24 -0
  59. package/dist/generic/src/authorization/jwt/sign/create-authorization-issuer.d.ts +10 -0
  60. package/dist/generic/src/authorization/jwt/sign/create-authorization-issuer.d.ts.map +1 -0
  61. package/dist/generic/src/authorization/jwt/sign/create-authorization-issuer.js +26 -0
  62. package/dist/generic/src/authorization/jwt/sign/create-authorization-subject.d.ts +12 -0
  63. package/dist/generic/src/authorization/jwt/sign/create-authorization-subject.d.ts.map +1 -0
  64. package/dist/generic/src/authorization/jwt/sign/create-authorization-subject.js +19 -0
  65. package/dist/generic/src/authorization/jwt/sign/create-jwt-options.d.ts +17 -0
  66. package/dist/generic/src/authorization/jwt/sign/create-jwt-options.d.ts.map +1 -0
  67. package/dist/generic/src/authorization/jwt/sign/create-jwt-options.js +43 -0
  68. package/dist/generic/src/authorization/jwt/sign/create-jwt-signed-token.d.ts +13 -0
  69. package/dist/generic/src/authorization/jwt/sign/create-jwt-signed-token.d.ts.map +1 -0
  70. package/dist/generic/src/authorization/jwt/sign/create-jwt-signed-token.js +22 -0
  71. package/dist/generic/src/authorization/jwt/transform/transform-token-payload-to-safe-payload.d.ts +10 -0
  72. package/dist/generic/src/authorization/jwt/transform/transform-token-payload-to-safe-payload.d.ts.map +1 -0
  73. package/dist/generic/src/authorization/jwt/transform/transform-token-payload-to-safe-payload.js +31 -0
  74. package/dist/generic/src/authorization/jwt/verify/get-decoded-jwt-header.d.ts +10 -0
  75. package/dist/generic/src/authorization/jwt/verify/get-decoded-jwt-header.d.ts.map +1 -0
  76. package/dist/generic/src/authorization/jwt/verify/get-decoded-jwt-header.js +20 -0
  77. package/dist/generic/src/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.d.ts +9 -0
  78. package/dist/generic/src/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.d.ts.map +1 -0
  79. package/dist/generic/src/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.js +17 -0
  80. package/dist/generic/src/authorization/jwt/verify/verify-jwt-signed-token.d.ts +12 -0
  81. package/dist/generic/src/authorization/jwt/verify/verify-jwt-signed-token.d.ts.map +1 -0
  82. package/dist/generic/src/authorization/jwt/verify/verify-jwt-signed-token.js +34 -0
  83. package/dist/generic/src/authorization/safe/authorization/authorized-authorities.d.ts +42 -0
  84. package/dist/generic/src/authorization/safe/authorization/authorized-authorities.d.ts.map +1 -0
  85. package/dist/generic/src/authorization/safe/authorization/authorized-authorities.js +65 -0
  86. package/dist/generic/src/authorization/safe/request/decode-bearer-token.d.ts +11 -0
  87. package/dist/generic/src/authorization/safe/request/decode-bearer-token.d.ts.map +1 -0
  88. package/dist/generic/src/authorization/safe/request/decode-bearer-token.js +31 -0
  89. package/dist/generic/src/authorization/safe/request/decode-safe-request.d.ts +11 -0
  90. package/dist/generic/src/authorization/safe/request/decode-safe-request.d.ts.map +1 -0
  91. package/dist/generic/src/authorization/safe/request/decode-safe-request.js +30 -0
  92. package/dist/generic/src/authorization/safe/request/determine-issuer-from-request.d.ts +10 -0
  93. package/dist/generic/src/authorization/safe/request/determine-issuer-from-request.d.ts.map +1 -0
  94. package/dist/generic/src/authorization/safe/request/determine-issuer-from-request.js +29 -0
  95. package/dist/generic/src/authorization/safe/request/issuer/determine-issuer-from-bearer-token.d.ts +12 -0
  96. package/dist/generic/src/authorization/safe/request/issuer/determine-issuer-from-bearer-token.d.ts.map +1 -0
  97. package/dist/generic/src/authorization/safe/request/issuer/determine-issuer-from-bearer-token.js +30 -0
  98. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-audience.d.ts +10 -0
  99. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-audience.d.ts.map +1 -0
  100. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-audience.js +24 -0
  101. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts +8 -0
  102. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts.map +1 -0
  103. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.js +23 -0
  104. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts +9 -0
  105. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts.map +1 -0
  106. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.js +24 -0
  107. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-issuer.d.ts +10 -0
  108. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-issuer.d.ts.map +1 -0
  109. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-issuer.js +25 -0
  110. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts +8 -0
  111. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts.map +1 -0
  112. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.js +23 -0
  113. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-subject.d.ts +10 -0
  114. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-subject.d.ts.map +1 -0
  115. package/dist/generic/src/authorization/safe/validation/jwt/payload/verify-authorization-subject.js +22 -0
  116. package/dist/generic/src/authorization/safe/validation/jwt/verify-token-header.d.ts +9 -0
  117. package/dist/generic/src/authorization/safe/validation/jwt/verify-token-header.d.ts.map +1 -0
  118. package/dist/generic/src/authorization/safe/validation/jwt/verify-token-header.js +25 -0
  119. package/dist/generic/src/authorization/safe/validation/jwt/verify-token-payload.d.ts +11 -0
  120. package/dist/generic/src/authorization/safe/validation/jwt/verify-token-payload.d.ts.map +1 -0
  121. package/dist/generic/src/authorization/safe/validation/jwt/verify-token-payload.js +30 -0
  122. package/dist/generic/src/errors/audit-log/audit-log-errors.d.ts +20 -0
  123. package/dist/generic/src/errors/audit-log/audit-log-errors.d.ts.map +1 -0
  124. package/dist/generic/src/errors/audit-log/audit-log-errors.js +31 -0
  125. package/dist/generic/src/errors/authorization/authorization-errors.d.ts +106 -0
  126. package/dist/generic/src/errors/authorization/authorization-errors.d.ts.map +1 -0
  127. package/dist/generic/src/errors/authorization/authorization-errors.js +160 -0
  128. package/dist/generic/src/errors/base-error.d.ts +23 -0
  129. package/dist/generic/src/errors/base-error.d.ts.map +1 -0
  130. package/dist/generic/src/errors/base-error.js +34 -0
  131. package/dist/generic/src/errors/database/database-errors.d.ts +24 -0
  132. package/dist/generic/src/errors/database/database-errors.d.ts.map +1 -0
  133. package/dist/generic/src/errors/database/database-errors.js +33 -0
  134. package/dist/generic/src/errors/generic/generic-errors.d.ts +35 -0
  135. package/dist/generic/src/errors/generic/generic-errors.d.ts.map +1 -0
  136. package/dist/generic/src/errors/generic/generic-errors.js +47 -0
  137. package/dist/generic/src/errors/index.d.ts +10 -0
  138. package/dist/generic/src/errors/index.d.ts.map +1 -0
  139. package/dist/generic/src/errors/index.js +26 -0
  140. package/dist/generic/src/errors/request/request-errors.d.ts +98 -0
  141. package/dist/generic/src/errors/request/request-errors.d.ts.map +1 -0
  142. package/dist/generic/src/errors/request/request-errors.js +134 -0
  143. package/dist/generic/src/errors/safe/safe-rules-errors.d.ts +102 -0
  144. package/dist/generic/src/errors/safe/safe-rules-errors.d.ts.map +1 -0
  145. package/dist/generic/src/errors/safe/safe-rules-errors.js +152 -0
  146. package/dist/generic/src/errors/scheduler/scheduler-errors.d.ts +8 -0
  147. package/dist/generic/src/errors/scheduler/scheduler-errors.d.ts.map +1 -0
  148. package/dist/generic/src/errors/scheduler/scheduler-errors.js +14 -0
  149. package/dist/generic/src/errors/share-data/share-data-errors.d.ts +67 -0
  150. package/dist/generic/src/errors/share-data/share-data-errors.d.ts.map +1 -0
  151. package/dist/generic/src/errors/share-data/share-data-errors.js +92 -0
  152. package/dist/generic/src/helpers/crypto/cryptography-helpers.d.ts +37 -0
  153. package/dist/generic/src/helpers/crypto/cryptography-helpers.d.ts.map +1 -0
  154. package/dist/generic/src/helpers/crypto/cryptography-helpers.js +65 -0
  155. package/dist/generic/src/helpers/object-validation-helpers.d.ts +66 -0
  156. package/dist/generic/src/helpers/object-validation-helpers.d.ts.map +1 -0
  157. package/dist/generic/src/helpers/object-validation-helpers.js +254 -0
  158. package/dist/generic/src/models/application/audit-log/application-audit-log-models.d.ts +87 -0
  159. package/dist/generic/src/models/application/audit-log/application-audit-log-models.d.ts.map +1 -0
  160. package/dist/generic/src/models/application/audit-log/application-audit-log-models.js +59 -0
  161. package/dist/generic/src/models/application/database/firestore-models.d.ts +84 -0
  162. package/dist/generic/src/models/application/database/firestore-models.d.ts.map +1 -0
  163. package/dist/generic/src/models/application/database/firestore-models.js +4 -0
  164. package/dist/generic/src/models/authorization/authorization-models.d.ts +81 -0
  165. package/dist/generic/src/models/authorization/authorization-models.d.ts.map +1 -0
  166. package/dist/generic/src/models/authorization/authorization-models.js +33 -0
  167. package/dist/generic/src/models/crypto/crypto-models.d.ts +5 -0
  168. package/dist/generic/src/models/crypto/crypto-models.d.ts.map +1 -0
  169. package/dist/generic/src/models/crypto/crypto-models.js +3 -0
  170. package/dist/generic/src/models/data/data-models.d.ts +24 -0
  171. package/dist/generic/src/models/data/data-models.d.ts.map +1 -0
  172. package/dist/generic/src/models/data/data-models.js +3 -0
  173. package/dist/generic/src/models/dynamic-execution/dynamic-execution-models.d.ts +9 -0
  174. package/dist/generic/src/models/dynamic-execution/dynamic-execution-models.d.ts.map +1 -0
  175. package/dist/generic/src/models/dynamic-execution/dynamic-execution-models.js +2 -0
  176. package/dist/generic/src/models/events/share-event-models.d.ts +65 -0
  177. package/dist/generic/src/models/events/share-event-models.d.ts.map +1 -0
  178. package/dist/generic/src/models/events/share-event-models.js +70 -0
  179. package/dist/generic/src/models/functions/share-data-function-models.d.ts +86 -0
  180. package/dist/generic/src/models/functions/share-data-function-models.d.ts.map +1 -0
  181. package/dist/generic/src/models/functions/share-data-function-models.js +17 -0
  182. package/dist/generic/src/models/generic/request-response-models.d.ts +8 -0
  183. package/dist/generic/src/models/generic/request-response-models.d.ts.map +1 -0
  184. package/dist/generic/src/models/generic/request-response-models.js +2 -0
  185. package/dist/generic/src/models/index.d.ts +13 -0
  186. package/dist/generic/src/models/index.d.ts.map +1 -0
  187. package/dist/generic/src/models/index.js +29 -0
  188. package/dist/generic/src/models/rules/share-rule-models.d.ts +303 -0
  189. package/dist/generic/src/models/rules/share-rule-models.d.ts.map +1 -0
  190. package/dist/generic/src/models/rules/share-rule-models.js +93 -0
  191. package/dist/generic/src/models/safe/safe-transaction-models.d.ts +81 -0
  192. package/dist/generic/src/models/safe/safe-transaction-models.d.ts.map +1 -0
  193. package/dist/generic/src/models/safe/safe-transaction-models.js +26 -0
  194. package/dist/generic/src/models/share-data/share-data.d.ts +56 -0
  195. package/dist/generic/src/models/share-data/share-data.d.ts.map +1 -0
  196. package/dist/generic/src/models/share-data/share-data.js +20 -0
  197. package/package.json +4 -3
  198. package/dist/cors/authority/audience/set-audience-authority.d.ts +0 -1
  199. package/dist/cors/authority/audience/set-audience-authority.d.ts.map +0 -1
  200. package/dist/cors/authority/audience/set-audience-authority.js +0 -1
  201. package/dist/cors/authority/jwt/validate-jwt-authority.d.ts +0 -1
  202. package/dist/cors/authority/jwt/validate-jwt-authority.d.ts.map +0 -1
  203. package/dist/cors/authority/jwt/validate-jwt-authority.js +0 -1
  204. package/dist/cors/errors/all-error-handler.d.ts.map +0 -1
  205. package/dist/cors/errors/bad-request-handler.d.ts +0 -12
  206. package/dist/cors/errors/bad-request-handler.d.ts.map +0 -1
  207. package/dist/cors/errors/unauthorized-handler.d.ts +0 -12
  208. package/dist/cors/errors/unauthorized-handler.d.ts.map +0 -1
  209. package/dist/cors/index.d.ts +0 -4
  210. package/dist/cors/index.d.ts.map +0 -1
  211. /package/dist/{index.d.ts → endpoints/src/index.d.ts} +0 -0
  212. /package/dist/{index.js → endpoints/src/index.js} +0 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createJwtOptions = void 0;
4
+ const authorization_models_1 = require("../../../models/authorization/authorization-models");
5
+ const authorization_settings_1 = require("../../../_settings/authorization-settings");
6
+ /**
7
+ * This function creates the options for the jwt token issuance
8
+ *
9
+ * @param subject the subject of the token
10
+ * @param audience the audience of the token (default is sharedata)
11
+ * @param algorithm the algorithm to use (default is ES512)
12
+ * @param expiresIn the expiration time of the token (default is 1 hour)
13
+ * @param notBefore the not before time of the token (default is 0)
14
+ * @param keyid A unique identifier for the key used to sign the token. This can be used to prevent replay attacks. (optional)
15
+ * @param header An object containing additional header properties to include in the token. (optional)
16
+ * @returns
17
+ */
18
+ const createJwtOptions = (subject, // the subject of the token
19
+ audience = authorization_models_1.AuthorizationAudience.SHAREDATA, // audience
20
+ algorithm = authorization_settings_1.AuthorizationSettings.JWT.Algorithm, // ECDSA using P-521 curve and SHA-512 hash algorithm
21
+ expiresIn = authorization_settings_1.AuthorizationSettings.JWT.ExpiresInDefault, // Default expiration time
22
+ notBefore = authorization_settings_1.AuthorizationSettings.JWT.NotBeforeDefault, // Default not before time
23
+ keyid, // A unique identifier for the key used to sign the token. This can be used to prevent replay attacks.
24
+ header) => {
25
+ const jwtOptions = {
26
+ subject,
27
+ audience,
28
+ algorithm,
29
+ expiresIn,
30
+ notBefore,
31
+ mutatePayload: authorization_settings_1.AuthorizationSettings.JWT.MutatePayload, // If true, the payload object will be mutated with the standard claims (iat, exp, etc.). Default is false.
32
+ noTimestamp: authorization_settings_1.AuthorizationSettings.JWT.NoTimestamp, // If true, the iat (issued at) claim will not be included in the token.
33
+ encoding: authorization_settings_1.AuthorizationSettings.JWT.EncodingDefault, // The encoding to use when converting the payload to a string.
34
+ allowInsecureKeySizes: authorization_settings_1.AuthorizationSettings.JWT.AllowInsecureKeySizes, // If true, allows the use of insecure key sizes.
35
+ allowInvalidAsymmetricKeyTypes: authorization_settings_1.AuthorizationSettings.JWT.AllowInvalidAsymmetricKeyTypes, // If true, allows the use of invalid asymmetric key types.
36
+ };
37
+ if (keyid)
38
+ jwtOptions.keyid = keyid;
39
+ if (header)
40
+ jwtOptions.header = header;
41
+ return jwtOptions;
42
+ };
43
+ exports.createJwtOptions = createJwtOptions;
@@ -0,0 +1,13 @@
1
+ import { IAuthorizationPayload } from '../../../models/authorization/authorization-models';
2
+ import jwt from 'jsonwebtoken';
3
+ /**
4
+ * This creates a signed JWT token with the given payload and secret key.
5
+ *
6
+ * @param payload the payload to sign
7
+ * @param secretKey the secret key to sign the token with
8
+ * @param options the options for the signed jwt token
9
+ * @returns
10
+ */
11
+ declare const createJWTSignedToken: (payload: IAuthorizationPayload, secretKey: string, options: jwt.SignOptions) => string;
12
+ export { createJWTSignedToken };
13
+ //# sourceMappingURL=create-jwt-signed-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-jwt-signed-token.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/jwt/sign/create-jwt-signed-token.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACxB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,GAAG,MAAM,cAAc,CAAC;AAG/B;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,YACb,qBAAqB,aACnB,MAAM,WACR,GAAG,CAAC,WAAW,KACzB,MAIF,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createJWTSignedToken = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const create_secret_key_pem_1 = require("../keys/create-secret-key-pem");
9
+ /**
10
+ * This creates a signed JWT token with the given payload and secret key.
11
+ *
12
+ * @param payload the payload to sign
13
+ * @param secretKey the secret key to sign the token with
14
+ * @param options the options for the signed jwt token
15
+ * @returns
16
+ */
17
+ const createJWTSignedToken = (payload, secretKey, options) => {
18
+ const jwtKey = (0, create_secret_key_pem_1.createSecretKeyPem)(secretKey);
19
+ const jwtToken = jsonwebtoken_1.default.sign(payload, jwtKey, options);
20
+ return jwtToken;
21
+ };
22
+ exports.createJWTSignedToken = createJWTSignedToken;
@@ -0,0 +1,10 @@
1
+ import { IDecodedJwtToken, IValidSafeTokenPayload } from '../../../models/authorization/authorization-models';
2
+ /**
3
+ * This function transforms the token payload to a safe payload with custom claims (if any).
4
+ *
5
+ * @param payload the payload to transform
6
+ * @returns the safe payload
7
+ */
8
+ declare const transformTokenPayloadToSafePayload: (payload: IValidSafeTokenPayload) => IDecodedJwtToken;
9
+ export { transformTokenPayloadToSafePayload };
10
+ //# sourceMappingURL=transform-token-payload-to-safe-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-token-payload-to-safe-payload.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/jwt/transform/transform-token-payload-to-safe-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,oDAAoD,CAAC;AAE9G;;;;;GAKG;AACH,QAAA,MAAM,kCAAkC,YAAa,sBAAsB,KAAG,gBAuB7E,CAAC;AAEF,OAAO,EAAE,kCAAkC,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformTokenPayloadToSafePayload = void 0;
4
+ /**
5
+ * This function transforms the token payload to a safe payload with custom claims (if any).
6
+ *
7
+ * @param payload the payload to transform
8
+ * @returns the safe payload
9
+ */
10
+ const transformTokenPayloadToSafePayload = (payload) => {
11
+ // get any other properties from the payload other than the default ones
12
+ const otherProperties = Object.keys(payload).reduce((acc, key) => {
13
+ if (!['iat', 'nbf', 'exp', 'sub', 'aud', 'iss'].includes(key)) {
14
+ acc[key] = payload[key];
15
+ }
16
+ return acc;
17
+ }, {});
18
+ const safePayload = {
19
+ iat: payload.iat,
20
+ nbf: payload.nbf,
21
+ exp: payload.exp,
22
+ sub: payload.sub,
23
+ aud: payload.aud,
24
+ iss: payload.iss,
25
+ };
26
+ if (Object.keys(otherProperties).length > 0) {
27
+ safePayload.customClaims = otherProperties;
28
+ }
29
+ return safePayload;
30
+ };
31
+ exports.transformTokenPayloadToSafePayload = transformTokenPayloadToSafePayload;
@@ -0,0 +1,10 @@
1
+ import { IAuthorizationHeader } from '../../../models/authorization/authorization-models';
2
+ /**
3
+ * This function gets the decoded jwt header from the token.
4
+ *
5
+ * @param token the token to get the header from.
6
+ * @returns
7
+ */
8
+ declare const getDecodedJwtHeader: (token: string) => IAuthorizationHeader;
9
+ export { getDecodedJwtHeader };
10
+ //# sourceMappingURL=get-decoded-jwt-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-decoded-jwt-header.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/jwt/verify/get-decoded-jwt-header.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAE1F;;;;;GAKG;AACH,QAAA,MAAM,mBAAmB,UAAW,MAAM,KAAG,oBAU5C,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDecodedJwtHeader = void 0;
4
+ const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
5
+ /**
6
+ * This function gets the decoded jwt header from the token.
7
+ *
8
+ * @param token the token to get the header from.
9
+ * @returns
10
+ */
11
+ const getDecodedJwtHeader = (token) => {
12
+ // break the token apart
13
+ const jwtTokenParts = token.split('.');
14
+ if (jwtTokenParts.length !== 3) {
15
+ throw new authorization_errors_1.SafeAuthorizationTokenNotBase64Error();
16
+ }
17
+ const header = JSON.parse(Buffer.from(jwtTokenParts[0], 'base64').toString('utf-8'));
18
+ return header;
19
+ };
20
+ exports.getDecodedJwtHeader = getDecodedJwtHeader;
@@ -0,0 +1,9 @@
1
+ import { JwtPayload } from 'jsonwebtoken';
2
+ /**
3
+ * This function gets the decoded payload from a signed JWT token.
4
+ *
5
+ * @param token the token to get the payload from
6
+ */
7
+ declare const getDecodedJwtSignedTokenPayload: (token: string) => JwtPayload | null | string;
8
+ export { getDecodedJwtSignedTokenPayload };
9
+ //# sourceMappingURL=get-decoded-jwt-signed-token-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-decoded-jwt-signed-token-payload.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.ts"],"names":[],"mappings":"AAAA,OAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;GAIG;AACH,QAAA,MAAM,+BAA+B,UAAW,MAAM,KAAG,UAAU,GAAG,IAAI,GAAG,MAG5E,CAAC;AAEF,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDecodedJwtSignedTokenPayload = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ /**
9
+ * This function gets the decoded payload from a signed JWT token.
10
+ *
11
+ * @param token the token to get the payload from
12
+ */
13
+ const getDecodedJwtSignedTokenPayload = (token) => {
14
+ const payload = jsonwebtoken_1.default.decode(token);
15
+ return payload;
16
+ };
17
+ exports.getDecodedJwtSignedTokenPayload = getDecodedJwtSignedTokenPayload;
@@ -0,0 +1,12 @@
1
+ import jwt from 'jsonwebtoken';
2
+ /**
3
+ * This verifies a JWT signed token with the given secret key or public key.
4
+ *
5
+ * @param tokenToVerify the jwt token to verify
6
+ * @param secretKey the secret key to verify the token with
7
+ * @param publicKey the public key to verify the token with
8
+ * @returns
9
+ */
10
+ declare const verifyJwtSignedToken: (tokenToVerify: string, secretKey?: string, publicKey?: string) => string | jwt.JwtPayload;
11
+ export { verifyJwtSignedToken };
12
+ //# sourceMappingURL=verify-jwt-signed-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-jwt-signed-token.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/jwt/verify/verify-jwt-signed-token.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAQ/B;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,kBACP,MAAM,cACT,MAAM,cACN,MAAM,KACnB,MAAM,GAAG,GAAG,CAAC,UAgBf,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.verifyJwtSignedToken = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
9
+ const create_public_key_pem_1 = require("../keys/create-public-key-pem");
10
+ const create_secret_key_pem_1 = require("../keys/create-secret-key-pem");
11
+ /**
12
+ * This verifies a JWT signed token with the given secret key or public key.
13
+ *
14
+ * @param tokenToVerify the jwt token to verify
15
+ * @param secretKey the secret key to verify the token with
16
+ * @param publicKey the public key to verify the token with
17
+ * @returns
18
+ */
19
+ const verifyJwtSignedToken = (tokenToVerify, secretKey, publicKey) => {
20
+ // break the token apart
21
+ const jwtTokenParts = tokenToVerify.split('.');
22
+ if (jwtTokenParts.length !== 3) {
23
+ throw new authorization_errors_1.SafeAuthorizationTokenNotBase64Error();
24
+ }
25
+ if (!secretKey && !publicKey) {
26
+ throw new authorization_errors_1.SafeAuthorizationKeyNotIncludedForVerificationError();
27
+ }
28
+ // create the key
29
+ const jwtKey = (secretKey) ? (0, create_secret_key_pem_1.createSecretKeyPem)(secretKey) : (0, create_public_key_pem_1.createPublicKeyPem)(publicKey);
30
+ // verify the token
31
+ const payload = jsonwebtoken_1.default.verify(tokenToVerify, jwtKey);
32
+ return payload;
33
+ };
34
+ exports.verifyJwtSignedToken = verifyJwtSignedToken;
@@ -0,0 +1,42 @@
1
+ import { AuthorizationAudience, IAuthorizationIssuer } from '../../../models/authorization/authorization-models';
2
+ /**
3
+ * This class is used to keep and maintain the authorized authorities in the SAFE system.
4
+ */
5
+ export declare class AuthorizedAuthorities {
6
+ private _authorizedJWTAuthorities;
7
+ private _currentJWTAuthoritiesHash;
8
+ constructor();
9
+ /**
10
+ * This adds a JWT authority to the authorized authorities for the given audience.
11
+ *
12
+ * @param audience the audience the authority is for
13
+ * @param authorizationIssuer the authority to add
14
+ * @param publicKey the public key
15
+ */
16
+ addAuthorizedJWTAuthority(audience: AuthorizationAudience, authorizationIssuer: IAuthorizationIssuer, publicKey: string): void;
17
+ /**
18
+ * This removes a JWT authority from the authorized authorities for the given audience.
19
+ *
20
+ * @param authority the authority to remove
21
+ */
22
+ removeAuthorizedJWTAuthority(audience: AuthorizationAudience, authority: IAuthorizationIssuer): void;
23
+ /**
24
+ * This gets the public key for the given authority for the given audience.
25
+ *
26
+ * @param authority the authority to get the public key for
27
+ * @returns
28
+ */
29
+ getAuthorizedJWTAuthorityPublicKey(audience: AuthorizationAudience, authority: IAuthorizationIssuer): string | undefined;
30
+ /**
31
+ * this gets the authorized JWT authorities for the given audience.
32
+ * @param audience the audience to get the authorized authorities for
33
+ * @returns
34
+ */
35
+ getAuthorizedJWTAuthorities(audience: AuthorizationAudience): Map<IAuthorizationIssuer, string>;
36
+ /**
37
+ * This gets the number of authorized JWT providers for the given audience.
38
+ * @returns
39
+ */
40
+ getAuthorizedJWTAuthoritiesCount(audience: AuthorizationAudience): number;
41
+ }
42
+ //# sourceMappingURL=authorized-authorities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorized-authorities.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/safe/authorization/authorized-authorities.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAiB,MAAM,oDAAoD,CAAC;AAEhI;;GAEG;AACH,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,yBAAyB,CAAgE;IAEjG,OAAO,CAAC,0BAA0B,CAAqC;;IAYtE;;;;;;MAME;IACI,yBAAyB,CAC5B,QAAQ,EAAE,qBAAqB,EAC/B,mBAAmB,EAAE,oBAAoB,EACzC,SAAS,EAAE,MAAM,GAClB,IAAI;IAKP;;;;OAIG;IACI,4BAA4B,CAAC,QAAQ,EAAE,qBAAqB,EAAE,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAO3G;;;;;OAKG;IACI,kCAAkC,CAAC,QAAQ,EAAE,qBAAqB,EAAE,SAAS,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS;IAI/H;;;;OAIG;IACI,2BAA2B,CAAC,QAAQ,EAAE,qBAAqB,GAAG,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAItG;;;OAGG;IACI,gCAAgC,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM;CAGnF"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthorizedAuthorities = void 0;
4
+ const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
5
+ const authorization_models_1 = require("../../../models/authorization/authorization-models");
6
+ /**
7
+ * This class is used to keep and maintain the authorized authorities in the SAFE system.
8
+ */
9
+ class AuthorizedAuthorities {
10
+ constructor() {
11
+ this._authorizedJWTAuthorities = new Map();
12
+ this._currentJWTAuthoritiesHash = new Map();
13
+ Object.values(authorization_models_1.AuthorizationAudience).forEach(audience => {
14
+ this._authorizedJWTAuthorities.set(audience, new Map());
15
+ this._currentJWTAuthoritiesHash.set(audience, '');
16
+ });
17
+ }
18
+ /**
19
+ * This adds a JWT authority to the authorized authorities for the given audience.
20
+ *
21
+ * @param audience the audience the authority is for
22
+ * @param authorizationIssuer the authority to add
23
+ * @param publicKey the public key
24
+ */
25
+ addAuthorizedJWTAuthority(audience, authorizationIssuer, publicKey) {
26
+ const audienceMap = this._authorizedJWTAuthorities.get(audience);
27
+ audienceMap?.set(authorizationIssuer, publicKey);
28
+ }
29
+ /**
30
+ * This removes a JWT authority from the authorized authorities for the given audience.
31
+ *
32
+ * @param authority the authority to remove
33
+ */
34
+ removeAuthorizedJWTAuthority(audience, authority) {
35
+ const removed = this._authorizedJWTAuthorities.get(audience)?.delete(authority);
36
+ if (!removed) {
37
+ throw new authorization_errors_1.SafeAuthorizationIssuerDoesNotExistError(authority);
38
+ }
39
+ }
40
+ /**
41
+ * This gets the public key for the given authority for the given audience.
42
+ *
43
+ * @param authority the authority to get the public key for
44
+ * @returns
45
+ */
46
+ getAuthorizedJWTAuthorityPublicKey(audience, authority) {
47
+ return this._authorizedJWTAuthorities.get(audience)?.get(authority);
48
+ }
49
+ /**
50
+ * this gets the authorized JWT authorities for the given audience.
51
+ * @param audience the audience to get the authorized authorities for
52
+ * @returns
53
+ */
54
+ getAuthorizedJWTAuthorities(audience) {
55
+ return this._authorizedJWTAuthorities.get(audience) || new Map();
56
+ }
57
+ /**
58
+ * This gets the number of authorized JWT providers for the given audience.
59
+ * @returns
60
+ */
61
+ getAuthorizedJWTAuthoritiesCount(audience) {
62
+ return this._authorizedJWTAuthorities.get(audience)?.size || 0;
63
+ }
64
+ }
65
+ exports.AuthorizedAuthorities = AuthorizedAuthorities;
@@ -0,0 +1,11 @@
1
+ import { IDecodedJwtToken } from '../../../models/authorization/authorization-models';
2
+ /**
3
+ * This function decodes the bearer token and verifies the issuer is as expected.
4
+ *
5
+ * @param bearerToken the bearer token to decode
6
+ * @param verificationKey the key to verify the token with
7
+ * @param issuerExpected the expected issuer of the token
8
+ */
9
+ declare const decodeBearerToken: (bearerToken: string, verificationKey: string, issuerExpected: string) => IDecodedJwtToken;
10
+ export { decodeBearerToken };
11
+ //# sourceMappingURL=decode-bearer-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-bearer-token.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/safe/request/decode-bearer-token.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AAKtF;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,gBAAiB,MAAM,mBAAmB,MAAM,kBAAkB,MAAM,KAAG,gBAkBjG,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeBearerToken = void 0;
4
+ const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
5
+ const transform_token_payload_to_safe_payload_1 = require("../../jwt/transform/transform-token-payload-to-safe-payload");
6
+ const verify_jwt_signed_token_1 = require("../../jwt/verify/verify-jwt-signed-token");
7
+ const verify_token_payload_1 = require("../validation/jwt/verify-token-payload");
8
+ /**
9
+ * This function decodes the bearer token and verifies the issuer is as expected.
10
+ *
11
+ * @param bearerToken the bearer token to decode
12
+ * @param verificationKey the key to verify the token with
13
+ * @param issuerExpected the expected issuer of the token
14
+ */
15
+ const decodeBearerToken = (bearerToken, verificationKey, issuerExpected) => {
16
+ const decodedToken = (0, verify_jwt_signed_token_1.verifyJwtSignedToken)(bearerToken, verificationKey);
17
+ if (!decodedToken || typeof decodedToken === 'string') {
18
+ throw new authorization_errors_1.SafeAuthorizationTokenNotObjectError();
19
+ }
20
+ if (issuerExpected !== decodedToken.iss) {
21
+ throw new authorization_errors_1.SafeAuthorizationIssuerNotMatchingExpectedError(issuerExpected, decodedToken.iss.toString());
22
+ }
23
+ // validate the token payload
24
+ if (!(0, verify_token_payload_1.verifyTokenPayload)(decodedToken)) {
25
+ throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
26
+ }
27
+ // transform the token payload to a safe payload
28
+ const decodedTokenPayload = (0, transform_token_payload_to_safe_payload_1.transformTokenPayloadToSafePayload)(decodedToken);
29
+ return decodedTokenPayload;
30
+ };
31
+ exports.decodeBearerToken = decodeBearerToken;
@@ -0,0 +1,11 @@
1
+ import { IDecodedJwtToken } from '../../../models/authorization/authorization-models';
2
+ /**
3
+ * This function decodes the safe request and returns the decoded token.
4
+ * This will throw an error if the request is not authorized.
5
+ *
6
+ * @param req the request to ensure authorization exists on.
7
+ * @returns
8
+ */
9
+ declare const decodeSafeRequest: (req: any, verificationKey: string, issuerExpected: string) => IDecodedJwtToken;
10
+ export { decodeSafeRequest };
11
+ //# sourceMappingURL=decode-safe-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-safe-request.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/safe/request/decode-safe-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AAEtF;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,QAAS,GAAG,mBAAmB,MAAM,kBAAkB,MAAM,KAAG,gBAatF,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeSafeRequest = void 0;
4
+ const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
5
+ const decode_bearer_token_1 = require("./decode-bearer-token");
6
+ /**
7
+ * This function decodes the safe request and returns the decoded token.
8
+ * This will throw an error if the request is not authorized.
9
+ *
10
+ * @param req the request to ensure authorization exists on.
11
+ * @returns
12
+ */
13
+ const decodeSafeRequest = (req, verificationKey, issuerExpected) => {
14
+ if (!req.headers)
15
+ throw new authorization_errors_1.SafeRequestAuthorizationHeadersNotFound();
16
+ if (!req.headers.authorization)
17
+ throw new authorization_errors_1.SafeRequestAuthorizationHeaderNotFound();
18
+ if (typeof req.headers.authorization === 'string' && req.headers.authorization.startsWith('Bearer ')) {
19
+ const bearerToken = req.headers.authorization.split('Bearer ')[1];
20
+ if (!bearerToken) {
21
+ throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
22
+ }
23
+ const decodedToken = (0, decode_bearer_token_1.decodeBearerToken)(bearerToken, verificationKey, issuerExpected);
24
+ return decodedToken;
25
+ }
26
+ else {
27
+ throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
28
+ }
29
+ };
30
+ exports.decodeSafeRequest = decodeSafeRequest;
@@ -0,0 +1,10 @@
1
+ import { IAuthorizationIssuer } from '../../../models/authorization/authorization-models';
2
+ /**
3
+ * This function determines the issuer from the request.
4
+ *
5
+ * @param req the request to determine the issuer from
6
+ * @returns
7
+ */
8
+ declare const determineIssuerFromRequest: (req: any) => IAuthorizationIssuer;
9
+ export { determineIssuerFromRequest };
10
+ //# sourceMappingURL=determine-issuer-from-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"determine-issuer-from-request.d.ts","sourceRoot":"","sources":["../../../../../../../generic/src/authorization/safe/request/determine-issuer-from-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAG1F;;;;;GAKG;AACH,QAAA,MAAM,0BAA0B,QAAS,GAAG,KAAG,oBAa9C,CAAA;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determineIssuerFromRequest = void 0;
4
+ const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
5
+ const determine_issuer_from_bearer_token_1 = require("./issuer/determine-issuer-from-bearer-token");
6
+ /**
7
+ * This function determines the issuer from the request.
8
+ *
9
+ * @param req the request to determine the issuer from
10
+ * @returns
11
+ */
12
+ const determineIssuerFromRequest = (req) => {
13
+ if (!req.headers)
14
+ throw new authorization_errors_1.SafeRequestAuthorizationHeadersNotFound();
15
+ if (!req.headers.authorization)
16
+ throw new authorization_errors_1.SafeRequestAuthorizationHeaderNotFound();
17
+ if (typeof req.headers.authorization === 'string' && req.headers.authorization.startsWith('Bearer ')) {
18
+ const bearerToken = req.headers.authorization.split('Bearer ')[1];
19
+ if (!bearerToken) {
20
+ throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
21
+ }
22
+ const issuer = (0, determine_issuer_from_bearer_token_1.determineIssuerFromBearerToken)(bearerToken);
23
+ return issuer;
24
+ }
25
+ else {
26
+ throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
27
+ }
28
+ };
29
+ exports.determineIssuerFromRequest = determineIssuerFromRequest;
@@ -0,0 +1,12 @@
1
+ import { IAuthorizationIssuer } from '../../../../models/authorization/authorization-models';
2
+ /**
3
+ * This function determines the issuer from the bearer token (if it exists).
4
+ * doesn't validate the signature of the token, just that the shape is correct and
5
+ * can be used to determine the signature to use to validate the token.
6
+ *
7
+ * @param bearerToken the bearer token to determine the issuer from
8
+ * @returns
9
+ */
10
+ declare const determineIssuerFromBearerToken: (bearerToken: string) => IAuthorizationIssuer;
11
+ export { determineIssuerFromBearerToken };
12
+ //# sourceMappingURL=determine-issuer-from-bearer-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"determine-issuer-from-bearer-token.d.ts","sourceRoot":"","sources":["../../../../../../../../generic/src/authorization/safe/request/issuer/determine-issuer-from-bearer-token.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uDAAuD,CAAC;AAI7F;;;;;;;GAOG;AACH,QAAA,MAAM,8BAA8B,gBAAiB,MAAM,KAAG,oBAiB7D,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.determineIssuerFromBearerToken = void 0;
4
+ const authorization_errors_1 = require("../../../../errors/authorization/authorization-errors");
5
+ const get_decoded_jwt_signed_token_payload_1 = require("../../../jwt/verify/get-decoded-jwt-signed-token-payload");
6
+ const verify_authorization_issuer_1 = require("../../validation/jwt/payload/verify-authorization-issuer");
7
+ /**
8
+ * This function determines the issuer from the bearer token (if it exists).
9
+ * doesn't validate the signature of the token, just that the shape is correct and
10
+ * can be used to determine the signature to use to validate the token.
11
+ *
12
+ * @param bearerToken the bearer token to determine the issuer from
13
+ * @returns
14
+ */
15
+ const determineIssuerFromBearerToken = (bearerToken) => {
16
+ const decodedToken = (0, get_decoded_jwt_signed_token_payload_1.getDecodedJwtSignedTokenPayload)(bearerToken); // get the payload from the token
17
+ if (decodedToken === null || typeof decodedToken === 'string') {
18
+ throw new authorization_errors_1.SafeAuthorizationTokenNotObjectError();
19
+ }
20
+ // make sure the iss property exists
21
+ if (!decodedToken.iss) {
22
+ throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('iss', decodedToken.iss, 'string');
23
+ }
24
+ // make sure the type is an issuer
25
+ if (!(0, verify_authorization_issuer_1.verifyAuthorizationIssuer)(decodedToken.iss)) {
26
+ throw new authorization_errors_1.SafeAuthorizationIssuerNotValidError(decodedToken.iss);
27
+ }
28
+ return decodedToken.iss;
29
+ };
30
+ exports.determineIssuerFromBearerToken = determineIssuerFromBearerToken;
@@ -0,0 +1,10 @@
1
+ import { AuthorizationAudience } from '../../../../../models/authorization/authorization-models';
2
+ /**
3
+ * This verifiies the audience of the token
4
+ *
5
+ * @param aud the audience to verify
6
+ * @returns
7
+ */
8
+ declare const verifyAuthorizationAudience: (aud: unknown) => aud is AuthorizationAudience;
9
+ export { verifyAuthorizationAudience };
10
+ //# sourceMappingURL=verify-authorization-audience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-authorization-audience.d.ts","sourceRoot":"","sources":["../../../../../../../../../generic/src/authorization/safe/validation/jwt/payload/verify-authorization-audience.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAC;AAEjG;;;;;GAKG;AACH,QAAA,MAAM,2BAA2B,QAAS,OAAO,KAAG,GAAG,IAAI,qBAc1D,CAAA;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyAuthorizationAudience = void 0;
4
+ const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
5
+ const authorization_models_1 = require("../../../../../models/authorization/authorization-models");
6
+ /**
7
+ * This verifiies the audience of the token
8
+ *
9
+ * @param aud the audience to verify
10
+ * @returns
11
+ */
12
+ const verifyAuthorizationAudience = (aud) => {
13
+ if (!aud) {
14
+ throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('aud');
15
+ }
16
+ if (typeof aud !== 'string') {
17
+ throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('aud', aud, 'string');
18
+ }
19
+ if (!Object.values(authorization_models_1.AuthorizationAudience).includes(aud)) {
20
+ throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
21
+ }
22
+ return true;
23
+ };
24
+ exports.verifyAuthorizationAudience = verifyAuthorizationAudience;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * this function validates the expiration time of the token hasn't passed
3
+ *
4
+ * @param exp the expiration time of the token
5
+ */
6
+ declare const verifyAuthorizationExpirationTime: (exp: unknown) => exp is number;
7
+ export { verifyAuthorizationExpirationTime };
8
+ //# sourceMappingURL=verify-authorization-expiration-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-authorization-expiration-time.d.ts","sourceRoot":"","sources":["../../../../../../../../../generic/src/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,QAAA,MAAM,iCAAiC,QAAS,OAAO,KAAG,GAAG,IAAI,MAchE,CAAC;AAEF,OAAO,EAAE,iCAAiC,EAAE,CAAC"}