From 2b66f6cf7bc464c51830252e34d24eaf017ef39e Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 20 Dec 2018 12:42:00 -0800 Subject: [PATCH] Release 10.0.0. Configure JwtAuthorizationRoute by passing in a sharedSecretProvider. Migrate from the previous version by passing in {sharedSecretProvider: new sharedSecret.RestSharedSecretProvider(...)}. --- dist/jwtauth/JwtAuthorizationRoute.d.ts | 3 +- dist/jwtauth/JwtAuthorizationRoute.js | 12 +- dist/jwtauth/JwtAuthorizationRoute.js.map | 2 +- .../jwtauth/JwtAuthorizationRouteOptions.d.ts | 5 +- dist/jwtauth/index.d.ts | 1 + dist/jwtauth/index.js | 4 + dist/jwtauth/index.js.map | 2 +- .../MerchantKeyProvider.d.ts | 3 - .../merchantSharedKey/MerchantKeyProvider.js | 3 - .../MerchantKeyProvider.js.map | 1 - .../RestMerchantKeyProvider.d.ts | 8 - .../RestMerchantKeyProvider.js | 32 ---- .../RestMerchantKeyProvider.js.map | 1 - dist/jwtauth/merchantSharedKey/StaticKey.d.ts | 6 - dist/jwtauth/merchantSharedKey/StaticKey.js | 22 --- .../merchantSharedKey/StaticKey.js.map | 1 - package-lock.json | 168 +++++++++--------- package.json | 24 +-- src/jwtauth/JwtAuthorizationRoute.test.ts | 17 +- src/jwtauth/JwtAuthorizationRoute.ts | 16 +- src/jwtauth/JwtAuthorizationRouteOptions.ts | 5 +- src/jwtauth/index.ts | 1 + .../merchantSharedKey/MerchantKeyProvider.ts | 5 - src/jwtauth/merchantSharedKey/StaticKey.ts | 13 -- .../RestSharedSecretProvider.ts} | 14 +- .../sharedSecret/SharedSecretProvider.ts | 7 + .../StaticSharedSecretProvider.ts | 11 ++ src/jwtauth/sharedSecret/index.ts | 3 + src/secureConfig/index.test.ts | 8 +- 29 files changed, 148 insertions(+), 250 deletions(-) delete mode 100644 dist/jwtauth/merchantSharedKey/MerchantKeyProvider.d.ts delete mode 100644 dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js delete mode 100644 dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js.map delete mode 100644 dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.d.ts delete mode 100644 dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js delete mode 100644 dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js.map delete mode 100644 dist/jwtauth/merchantSharedKey/StaticKey.d.ts delete mode 100644 dist/jwtauth/merchantSharedKey/StaticKey.js delete mode 100644 dist/jwtauth/merchantSharedKey/StaticKey.js.map delete mode 100644 src/jwtauth/merchantSharedKey/MerchantKeyProvider.ts delete mode 100644 src/jwtauth/merchantSharedKey/StaticKey.ts rename src/jwtauth/{merchantSharedKey/RestMerchantKeyProvider.ts => sharedSecret/RestSharedSecretProvider.ts} (53%) create mode 100644 src/jwtauth/sharedSecret/SharedSecretProvider.ts create mode 100644 src/jwtauth/sharedSecret/StaticSharedSecretProvider.ts create mode 100644 src/jwtauth/sharedSecret/index.ts diff --git a/dist/jwtauth/JwtAuthorizationRoute.d.ts b/dist/jwtauth/JwtAuthorizationRoute.d.ts index 7a92a79..cabe766 100644 --- a/dist/jwtauth/JwtAuthorizationRoute.d.ts +++ b/dist/jwtauth/JwtAuthorizationRoute.d.ts @@ -1,5 +1,4 @@ import * as cassava from "cassava"; -import { MerchantKeyProvider } from "./merchantSharedKey/MerchantKeyProvider"; import { JwtAuthorizationRouteOptions } from "./JwtAuthorizationRouteOptions"; export declare class JwtAuthorizationRoute implements cassava.routes.Route { private readonly options; @@ -7,7 +6,7 @@ export declare class JwtAuthorizationRoute implements cassava.routes.Route { private readonly errorLogFunction?; private readonly authConfigPromise; private readonly rolesConfigPromise?; - readonly merchantKeyProvider: MerchantKeyProvider; + private readonly sharedSecretProvider; constructor(options: JwtAuthorizationRouteOptions); handle(evt: cassava.RouterEvent): Promise; postProcess(evt: cassava.RouterEvent, resp: cassava.RouterResponse): Promise; diff --git a/dist/jwtauth/JwtAuthorizationRoute.js b/dist/jwtauth/JwtAuthorizationRoute.js index c1266fc..0f48368 100644 --- a/dist/jwtauth/JwtAuthorizationRoute.js +++ b/dist/jwtauth/JwtAuthorizationRoute.js @@ -12,7 +12,6 @@ const cassava = require("cassava"); const jwt = require("jsonwebtoken"); const AuthorizationBadge_1 = require("./AuthorizationBadge"); const AuthorizationHeader_1 = require("./AuthorizationHeader"); -const RestMerchantKeyProvider_1 = require("./merchantSharedKey/RestMerchantKeyProvider"); class JwtAuthorizationRoute { constructor(options) { this.options = options; @@ -22,12 +21,7 @@ class JwtAuthorizationRoute { this.errorLogFunction = options.errorLogFunction || this.errorLogFunction; this.authConfigPromise = options.authConfigPromise; this.rolesConfigPromise = options.rolesConfigPromise; - if (options.merchantKeyUri && options.assumeGetSharedSecretToken) { - this.merchantKeyProvider = new RestMerchantKeyProvider_1.RestMerchantKeyProvider(options.merchantKeyUri, options.assumeGetSharedSecretToken); - } - else if (options.merchantKeyUri || options.assumeGetSharedSecretToken) { - throw new Error("Configuration error. You must provide both the merchantKeyUri and the assumeGetSharedSecretToken or neither."); - } + this.sharedSecretProvider = options.sharedSecretProvider; } handle(evt) { return __awaiter(this, void 0, void 0, function* () { @@ -133,10 +127,10 @@ class JwtAuthorizationRoute { } let secret; if (unverifiedAuthPayload.iss === "MERCHANT") { - if (!this.merchantKeyProvider) { + if (!this.sharedSecretProvider) { throw new Error("Merchant key provider has not been configured. Not accepting merchant signed tokens."); } - secret = yield this.merchantKeyProvider.getMerchantKey(token); + secret = yield this.sharedSecretProvider.getSharedSecret(token); if (!secret) { throw new Error("Secret is null. Check that the merchant has set a shared secret."); } diff --git a/dist/jwtauth/JwtAuthorizationRoute.js.map b/dist/jwtauth/JwtAuthorizationRoute.js.map index 169cba2..a36b2c9 100644 --- a/dist/jwtauth/JwtAuthorizationRoute.js.map +++ b/dist/jwtauth/JwtAuthorizationRoute.js.map @@ -1 +1 @@ -{"version":3,"file":"JwtAuthorizationRoute.js","sourceRoot":"","sources":["../../src/jwtauth/JwtAuthorizationRoute.ts"],"names":[],"mappings":";;;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E;gBAC1C,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;oBAC3B,MAAM,IAAI,KAAK,CAAC,uFAAuF,CAAC,CAAC;iBAC5G;gBACD,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;gBAC9D,IAAI,CAAC,MAAM,EAAE;oBACT,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;iBACxF;aACJ;iBAAM;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC;gBAC/C,IAAI,CAAC,SAAS,EAAE;oBACZ,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;iBAC5F;gBACD,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC;aAChC;YAED,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE;gBAC1C,gBAAgB,EAAE,KAAK;gBACvB,UAAU,EAAE,CAAC,OAAO,CAAC;aACxB,CAAW,CAAC;YACb,OAAO,IAAI,uCAAkB,CAAC,WAAW,EAAE;gBACvC,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI;gBAC3E,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;aAC1C,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AAzJD,sDAyJC"} \ No newline at end of file +{"version":3,"file":"JwtAuthorizationRoute.js","sourceRoot":"","sources":["../../src/jwtauth/JwtAuthorizationRoute.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,mCAAmC;AACnC,oCAAoC;AACpC,6DAAwD;AACxD,+DAA0D;AAO1D,MAAa,qBAAqB;IAQ9B,YAA6B,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;QANjD,oBAAe,GAA6B,OAAO,CAAC,GAAG,CAAC,I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F;gBACD,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC;aAChC;YAED,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE;gBAC1C,gBAAgB,EAAE,KAAK;gBACvB,UAAU,EAAE,CAAC,OAAO,CAAC;aACxB,CAAW,CAAC;YACb,OAAO,IAAI,uCAAkB,CAAC,WAAW,EAAE;gBACvC,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI;gBAC3E,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;aAC1C,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AApJD,sDAoJC"} \ No newline at end of file diff --git a/dist/jwtauth/JwtAuthorizationRouteOptions.d.ts b/dist/jwtauth/JwtAuthorizationRouteOptions.d.ts index 5a5e8ea..1807b9b 100644 --- a/dist/jwtauth/JwtAuthorizationRouteOptions.d.ts +++ b/dist/jwtauth/JwtAuthorizationRouteOptions.d.ts @@ -1,11 +1,10 @@ import { AuthenticationConfig } from "../secureConfig"; import { RolesConfig } from "../secureConfig"; -import { AssumeScopeToken } from "../secureConfig"; +import { SharedSecretProvider } from "./sharedSecret/SharedSecretProvider"; export interface JwtAuthorizationRouteOptions { authConfigPromise: Promise; rolesConfigPromise?: Promise; - merchantKeyUri?: string; - assumeGetSharedSecretToken?: Promise; + sharedSecretProvider?: SharedSecretProvider; infoLogFunction?: (...msg: any[]) => void; errorLogFunction?: (...msg: any[]) => void; } diff --git a/dist/jwtauth/index.d.ts b/dist/jwtauth/index.d.ts index 67bb662..e9e5ad4 100644 --- a/dist/jwtauth/index.d.ts +++ b/dist/jwtauth/index.d.ts @@ -3,3 +3,4 @@ export { AuthorizationHeader } from "./AuthorizationHeader"; export { JwtAuthorizationRoute } from "./JwtAuthorizationRoute"; export { JwtHeader } from "./JwtHeader"; export { JwtPayload } from "./JwtPayload"; +export * from "./sharedSecret"; diff --git a/dist/jwtauth/index.js b/dist/jwtauth/index.js index 3d7a470..0efa45b 100644 --- a/dist/jwtauth/index.js +++ b/dist/jwtauth/index.js @@ -1,4 +1,7 @@ "use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} Object.defineProperty(exports, "__esModule", { value: true }); var AuthorizationBadge_1 = require("./AuthorizationBadge"); exports.AuthorizationBadge = AuthorizationBadge_1.AuthorizationBadge; @@ -8,4 +11,5 @@ var JwtAuthorizationRoute_1 = require("./JwtAuthorizationRoute"); exports.JwtAuthorizationRoute = JwtAuthorizationRoute_1.JwtAuthorizationRoute; var JwtPayload_1 = require("./JwtPayload"); exports.JwtPayload = JwtPayload_1.JwtPayload; +__export(require("./sharedSecret")); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/jwtauth/index.js.map b/dist/jwtauth/index.js.map index 762db32..cbe84c3 100644 --- a/dist/jwtauth/index.js.map +++ b/dist/jwtauth/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jwtauth/index.ts"],"names":[],"mappings":";;AAAA,2DAAwD;AAAhD,kDAAA,kBAAkB,CAAA;AAC1B,6DAA0D;AAAlD,oDAAA,mBAAmB,CAAA;AAC3B,iEAA8D;AAAtD,wDAAA,qBAAqB,CAAA;AAE7B,2CAAwC;AAAhC,kCAAA,UAAU,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jwtauth/index.ts"],"names":[],"mappings":";;;;;AAAA,2DAAwD;AAAhD,kDAAA,kBAAkB,CAAA;AAC1B,6DAA0D;AAAlD,oDAAA,mBAAmB,CAAA;AAC3B,iEAA8D;AAAtD,wDAAA,qBAAqB,CAAA;AAE7B,2CAAwC;AAAhC,kCAAA,UAAU,CAAA;AAClB,oCAA+B"} \ No newline at end of file diff --git a/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.d.ts b/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.d.ts deleted file mode 100644 index b45cdd0..0000000 --- a/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface MerchantKeyProvider { - getMerchantKey(token: string): Promise; -} diff --git a/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js b/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js deleted file mode 100644 index d4de3f5..0000000 --- a/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=MerchantKeyProvider.js.map \ No newline at end of file diff --git a/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js.map b/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js.map deleted file mode 100644 index 6df766d..0000000 --- a/dist/jwtauth/merchantSharedKey/MerchantKeyProvider.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"MerchantKeyProvider.js","sourceRoot":"","sources":["../../../src/jwtauth/merchantSharedKey/MerchantKeyProvider.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.d.ts b/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.d.ts deleted file mode 100644 index acc75c6..0000000 --- a/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { AssumeScopeToken } from "../../secureConfig"; -import { MerchantKeyProvider } from "./MerchantKeyProvider"; -export declare class RestMerchantKeyProvider implements MerchantKeyProvider { - private readonly merchantKeyUri; - private readonly assumeGetSharedSecretToken; - constructor(merchantKeyUri: string, assumeGetSharedSecretToken: Promise); - getMerchantKey(token: string): Promise; -} diff --git a/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js b/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js deleted file mode 100644 index d8ef85f..0000000 --- a/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const superagent = require("superagent"); -class RestMerchantKeyProvider { - constructor(merchantKeyUri, assumeGetSharedSecretToken) { - this.merchantKeyUri = merchantKeyUri; - this.assumeGetSharedSecretToken = assumeGetSharedSecretToken; - if (!/^https?:\/\//.test(this.merchantKeyUri)) { - this.merchantKeyUri = "https://" + this.merchantKeyUri; - } - } - getMerchantKey(token) { - return __awaiter(this, void 0, void 0, function* () { - const tokenPayload = token.split(".")[1]; - const storageTokenConfig = yield this.assumeGetSharedSecretToken; - const resp = yield superagent("GET", this.merchantKeyUri) - .set("Authorization", `Bearer ${storageTokenConfig.assumeToken}`) - .set("AuthorizeAs", tokenPayload); - return resp.body; - }); - } -} -exports.RestMerchantKeyProvider = RestMerchantKeyProvider; -//# sourceMappingURL=RestMerchantKeyProvider.js.map \ No newline at end of file diff --git a/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js.map b/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js.map deleted file mode 100644 index e8b5441..0000000 --- a/dist/jwtauth/merchantSharedKey/RestMerchantKeyProvider.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"RestMerchantKeyProvider.js","sourceRoot":"","sources":["../../../src/jwtauth/merchantSharedKey/RestMerchantKeyProvider.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,yCAAyC;AAIzC,MAAa,uBAAuB;IAEhC,YACqB,cAAsB,EACtB,0BAAqD;QADrD,mBAAc,GAAd,cAAc,CAAQ;QACtB,+BAA0B,GAA1B,0BAA0B,CAA2B;QAEtE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;YAC3C,IAAI,CAAC,cAAc,GAAG,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC;SAC1D;IACL,CAAC;IAEK,cAAc,CAAC,KAAa;;YAC9B,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,0BAA0B,CAAC;YACjE,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC;iBACpD,GAAG,CAAC,eAAe,EAAE,UAAU,kBAAkB,CAAC,WAAW,EAAE,CAAC;iBAChE,GAAG,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC;KAAA;CACJ;AAnBD,0DAmBC"} \ No newline at end of file diff --git a/dist/jwtauth/merchantSharedKey/StaticKey.d.ts b/dist/jwtauth/merchantSharedKey/StaticKey.d.ts deleted file mode 100644 index 7673a91..0000000 --- a/dist/jwtauth/merchantSharedKey/StaticKey.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { MerchantKeyProvider } from "./MerchantKeyProvider"; -export declare class StaticKey implements MerchantKeyProvider { - private readonly key; - constructor(key: string); - getMerchantKey(token: string): Promise; -} diff --git a/dist/jwtauth/merchantSharedKey/StaticKey.js b/dist/jwtauth/merchantSharedKey/StaticKey.js deleted file mode 100644 index a28be03..0000000 --- a/dist/jwtauth/merchantSharedKey/StaticKey.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -class StaticKey { - constructor(key) { - this.key = key; - } - getMerchantKey(token) { - return __awaiter(this, void 0, void 0, function* () { - return Promise.resolve(this.key); - }); - } -} -exports.StaticKey = StaticKey; -//# sourceMappingURL=StaticKey.js.map \ No newline at end of file diff --git a/dist/jwtauth/merchantSharedKey/StaticKey.js.map b/dist/jwtauth/merchantSharedKey/StaticKey.js.map deleted file mode 100644 index b172088..0000000 --- a/dist/jwtauth/merchantSharedKey/StaticKey.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"StaticKey.js","sourceRoot":"","sources":["../../../src/jwtauth/merchantSharedKey/StaticKey.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,MAAa,SAAS;IAElB,YACqB,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAC7B,CAAC;IAEE,cAAc,CAAC,KAAa;;YAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC;KAAA;CACJ;AATD,8BASC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index efa058d..f1829c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "giftbit-cassava-routes", - "version": "9.0.1", + "version": "10.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -14,35 +14,29 @@ } }, "@sinonjs/formatio": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.0.0.tgz", - "integrity": "sha512-vdjoYLDptCgvtJs57ULshak3iJe4NW3sJ3g36xVDGff5AE8P30S6A093EIEPjdi2noGhfuNOEkbxt3J3awFW1w==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.1.0.tgz", + "integrity": "sha512-ZAR2bPHOl4Xg6eklUGpsdiIJ4+J1SNag1DHHrG/73Uz/nVwXqjgUtRPLoS+aVyieN9cSbc0E4LsU984tWcDyNg==", "dev": true, "requires": { - "@sinonjs/samsam": "2.1.0" - }, - "dependencies": { - "@sinonjs/samsam": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.0.tgz", - "integrity": "sha512-5x2kFgJYupaF1ns/RmharQ90lQkd2ELS8A9X0ymkAAdemYHGtI2KiUHG8nX2WU0T1qgnOU5YMqnBM2V7NUanNw==", - "dev": true, - "requires": { - "array-from": "^2.1.1" - } - } + "@sinonjs/samsam": "^2 || ^3" } }, "@sinonjs/samsam": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-2.1.2.tgz", - "integrity": "sha512-ZwTHAlC9akprWDinwEPD4kOuwaYZlyMwVJIANsKNC3QVp0AHB04m7RnB4eqeWfgmxw8MGTzS9uMaw93Z3QcZbw==", - "dev": true + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.0.2.tgz", + "integrity": "sha512-m08g4CS3J6lwRQk1pj1EO+KEVWbrbXsmi9Pw0ySmrIbcVxVaedoFgLvFsV8wHLwh01EpROVz3KvVcD1Jmks9FQ==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.0.2", + "array-from": "^2.1.1", + "lodash.get": "^4.4.2" + } }, "@types/aws-lambda": { - "version": "8.10.14", - "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.14.tgz", - "integrity": "sha512-dBVxru7n7Q2oYDR1wEqqIEizrb2p1IQ0Rz0sxsiY6FLfx65JuU8kS58PGnAf4KUcM4QURyMq2sTPA01wR6y/Ig==", + "version": "8.10.17", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.17.tgz", + "integrity": "sha512-KV/9fMAvv5428/v4+AP4nDOfSB4sJIBOGgBtv5YbuQVaAEapL1/Bc8IyACZ48Q3hYukVFjzAdVFq94zTxyd5Yw==", "dev": true }, "@types/chai": { @@ -52,9 +46,9 @@ "dev": true }, "@types/cookie": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.1.tgz", - "integrity": "sha512-64Uv+8bTRVZHlbB8eXQgMP9HguxPgnOOIYrQpwHWrtLDrtcG/lILKhUl7bV65NSOIJ9dXGYD7skQFXzhL8tk1A==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.2.tgz", + "integrity": "sha512-aHQA072E10/8iUQsPH7mQU/KUyQBZAGzTVRCUvnSz8mSvbrYsP4xEO2RSA0Pjltolzi0j8+8ixrm//Hr4umPzw==", "dev": true }, "@types/cookiejar": { @@ -70,9 +64,9 @@ "dev": true }, "@types/jsonwebtoken": { - "version": "7.2.8", - "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-7.2.8.tgz", - "integrity": "sha512-XENN3YzEB8D6TiUww0O8SRznzy1v+77lH7UmuN54xq/IHIsyWjWOzZuFFTtoiRuaE782uAoRwBe/wwow+vQXZw==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.3.0.tgz", + "integrity": "sha512-YKnUTR4VxwljbPORPrRon9E3uel1aD8nUdvzqArCCdMTWPvo0gnI2UZkwIHN2QATdj6HYXV/Iq3/KcecAO42Ww==", "dev": true, "requires": { "@types/node": "*" @@ -85,9 +79,9 @@ "dev": true }, "@types/node": { - "version": "10.12.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.1.tgz", - "integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ==", + "version": "10.12.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz", + "integrity": "sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==", "dev": true }, "@types/raven": { @@ -101,15 +95,15 @@ } }, "@types/sinon": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-5.0.5.tgz", - "integrity": "sha512-Wnuv66VhvAD2LEJfZkq8jowXGxe+gjVibeLCYcVBp7QLdw0BFx2sRkKzoiiDkYEPGg5VyqO805Rcj0stVjQwCQ==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-7.0.2.tgz", + "integrity": "sha512-YvJOqPk4kh1eQyxuASDD4MDK27XWAhtw6hJ7rRayEOkkTpZkqDWpDb4OjLVzFGdapOuUgZdnqO+71Q3utCJtcA==", "dev": true }, "@types/superagent": { - "version": "3.8.4", - "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-3.8.4.tgz", - "integrity": "sha512-Dnh0Iw6NO55z1beXvlsvUrfk4cd9eL2nuTmUk+rAhSVCk10PGGFbqCCTwbau9D0d2W3DITiXl4z8VCqppGkMPQ==", + "version": "3.8.5", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-3.8.5.tgz", + "integrity": "sha512-h7dQyzEGQFY3Ya8pIu0fxcWaMWC2DDSKR78gHrh6GVnXUqXo/+93wd4RObXA13rKp4ETyym3yq2A0AxROx9AxQ==", "dev": true, "requires": { "@types/cookiejar": "*", @@ -161,9 +155,9 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "aws-sdk": { - "version": "2.344.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.344.0.tgz", - "integrity": "sha512-VGiVgX4+qk/67o8GL3qeHK1KC4r73jlsJoE6ZSPsujX6UjP0PgrfUL1J9cdW/sgXc0lzmK3ksdKqZordFZ4/xw==", + "version": "2.380.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.380.0.tgz", + "integrity": "sha512-V0en7O9cCOY4Vb99SFzT51YQ0gn3MhWK2T7SzRGKMjETQo4/PVlflEaBIkaJJlhDXrVzgZ+Fmft/tHEetTk44w==", "dev": true, "requires": { "buffer": "4.9.1", @@ -198,7 +192,7 @@ "dependencies": { "chalk": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { @@ -333,18 +327,18 @@ "dev": true }, "color-convert": { - "version": "1.9.2", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.2.tgz", - "integrity": "sha512-3NUJZdhMhcdPn8vJ9v2UQJoH0qqoGUkYTgFEPZaPjEtwmmKUfNV46zZmgB2M5M4DCEQHMaCfWHCxiBflLm04Tg==", + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "dev": true, "requires": { - "color-name": "1.1.1" + "color-name": "1.1.3" } }, "color-name": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.1.tgz", - "integrity": "sha1-SxQVMEz1ACjqgWQ2Q72C6gWANok=", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, "combined-stream": { @@ -592,9 +586,9 @@ "dev": true }, "jsonwebtoken": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.3.0.tgz", - "integrity": "sha512-oge/hvlmeJCH+iIz1DwcO7vKPkNGJHhgkspk8OH3VKlw+mbi42WtD4ig1+VXRln765vxptAv+xT26Fd3cteqag==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.4.0.tgz", + "integrity": "sha512-coyXjRTCy0pw5WYBpMvWOMN+Kjaik2MwTUIq9cna/W7NpO9E+iYbumZONAz3hcr+tXFJECoQVrtmIoC3Oz0gvg==", "requires": { "jws": "^3.1.5", "lodash.includes": "^4.3.0", @@ -608,9 +602,9 @@ } }, "just-extend": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-3.0.0.tgz", - "integrity": "sha512-Fu3T6pKBuxjWT/p4DkqGHFRsysc8OauWr4ZRTY9dIx07Y9O0RkoR5jcv28aeD1vuAwhm3nLkDurwLXoALp4DpQ==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz", + "integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==", "dev": true }, "jwa": { @@ -789,13 +783,13 @@ "dev": true }, "nise": { - "version": "1.4.6", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.4.6.tgz", - "integrity": "sha512-1GedetLKzmqmgwabuMSqPsT7oumdR77SBpDfNNJhADRIeA3LN/2RVqR4fFqwvzhAqcTef6PPCzQwITE/YQ8S8A==", + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.4.8.tgz", + "integrity": "sha512-kGASVhuL4tlAV0tvA34yJYZIVihrUt/5bDwpp4tTluigxUr2bBlJeDXmivb6NuEdFkqvdv/Ybb9dm16PSKUhtw==", "dev": true, "requires": { - "@sinonjs/formatio": "3.0.0", - "just-extend": "^3.0.0", + "@sinonjs/formatio": "^3.1.0", + "just-extend": "^4.0.2", "lolex": "^2.3.2", "path-to-regexp": "^1.7.0", "text-encoding": "^0.6.4" @@ -825,9 +819,9 @@ "dev": true }, "path-parse": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", - "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, "path-to-regexp": { @@ -902,12 +896,12 @@ } }, "resolve": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", - "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz", + "integrity": "sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==", "dev": true, "requires": { - "path-parse": "^1.0.5" + "path-parse": "^1.0.6" } }, "rimraf": { @@ -931,26 +925,24 @@ "dev": true }, "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", "dev": true }, "sinon": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.1.0.tgz", - "integrity": "sha512-ffASxced8xr8eU0EGyfj9K++bRCtv/NyOFOxl7UBD86YH97oZjVxvecMhObwRlXe27GRUa6rVFEn67khPZ29rQ==", + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.2.2.tgz", + "integrity": "sha512-WLagdMHiEsrRmee3jr6IIDntOF4kbI6N2pfbi8wkv50qaUQcBglkzkjtoOEbeJ2vf1EsrHhLI+5Ny8//WHdMoA==", "dev": true, "requires": { - "@sinonjs/commons": "^1.0.2", - "@sinonjs/formatio": "^3.0.0", - "@sinonjs/samsam": "^2.1.2", + "@sinonjs/commons": "^1.2.0", + "@sinonjs/formatio": "^3.1.0", + "@sinonjs/samsam": "^3.0.2", "diff": "^3.5.0", - "lodash.get": "^4.4.2", "lolex": "^3.0.0", - "nise": "^1.4.6", - "supports-color": "^5.5.0", - "type-detect": "^4.0.8" + "nise": "^1.4.7", + "supports-color": "^5.5.0" }, "dependencies": { "supports-color": { @@ -982,7 +974,7 @@ }, "sprintf-js": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "resolved": "http://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, @@ -1001,7 +993,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { @@ -1076,9 +1068,9 @@ "dev": true }, "tslint": { - "version": "5.11.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz", - "integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=", + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.12.0.tgz", + "integrity": "sha512-CKEcH1MHUBhoV43SA/Jmy1l24HJJgI0eyLbBNSRyFlsQvb9v6Zdq+Nz2vEOH00nC5SUx4SneJ59PZUS/ARcokQ==", "dev": true, "requires": { "babel-code-frame": "^6.22.0", @@ -1111,9 +1103,9 @@ "dev": true }, "typescript": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.3.tgz", - "integrity": "sha512-+81MUSyX+BaSo+u2RbozuQk/UWx6hfG0a5gHu4ANEM4sU96XbuIyAB+rWBW1u70c6a5QuZfuYICn3s2UjuHUpA==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz", + "integrity": "sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==", "dev": true }, "url": { diff --git a/package.json b/package.json index fdf8e6e..b6052ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "giftbit-cassava-routes", - "version": "9.0.2", + "version": "10.0.0", "description": "Private Giftbit routes for use with Cassava.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -28,27 +28,27 @@ "cassava": "^2.3.0" }, "devDependencies": { - "@types/aws-lambda": "^8.10.14", + "@types/aws-lambda": "^8.10.17", "@types/chai": "^4.1.7", - "@types/cookie": "^0.3.1", - "@types/jsonwebtoken": "^7.2.8", + "@types/cookie": "^0.3.2", + "@types/jsonwebtoken": "^8.3.0", "@types/mocha": "^5.2.5", - "@types/node": "^10.12.1", + "@types/node": "^10.12.18", "@types/raven": "^2.5.1", - "@types/sinon": "^5.0.5", - "@types/superagent": "^3.8.4", - "aws-sdk": "^2.344.0", + "@types/sinon": "^7.0.2", + "@types/superagent": "^3.8.5", + "aws-sdk": "^2.380.0", "cassava": "^2.3.0", "chai": "^4.2.0", "mocha": "^5.2.0", "rimraf": "^2.6.2", - "sinon": "^7.1.0", + "sinon": "^7.2.2", "ts-node": "^7.0.1", - "tslint": "^5.11.0", - "typescript": "^3.1.3" + "tslint": "^5.12.0", + "typescript": "^3.2.2" }, "dependencies": { - "jsonwebtoken": "^8.3.0", + "jsonwebtoken": "^8.4.0", "raven": "^2.6.4", "superagent": "^3.8.3" } diff --git a/src/jwtauth/JwtAuthorizationRoute.test.ts b/src/jwtauth/JwtAuthorizationRoute.test.ts index f4fb2d7..280b7cf 100644 --- a/src/jwtauth/JwtAuthorizationRoute.test.ts +++ b/src/jwtauth/JwtAuthorizationRoute.test.ts @@ -2,9 +2,8 @@ import * as cassava from "cassava"; import * as chai from "chai"; import {JwtAuthorizationRoute} from "./JwtAuthorizationRoute"; import {AuthorizationBadge} from "./AuthorizationBadge"; -import {StaticKey} from "./merchantSharedKey/StaticKey"; -import {MerchantKeyProvider} from "./merchantSharedKey/MerchantKeyProvider"; import nodeUtil = require("util"); +import {StaticSharedSecretProvider} from "./sharedSecret"; describe("JwtAuthorizationRoute", () => { @@ -507,27 +506,17 @@ describe("JwtAuthorizationRoute", () => { }); describe("merchant self signing support", () => { - let staticKey: StaticKey; let router: cassava.Router; let jwtAuthorizationRoute: JwtAuthorizationRoute; - let originalMerchantKeyProvider: MerchantKeyProvider; beforeEach(() => { router = new cassava.Router(); jwtAuthorizationRoute = new JwtAuthorizationRoute({ authConfigPromise, - merchantKeyUri: "http://someUuri", - assumeGetSharedSecretToken: Promise.resolve({assumeToken: "secret"}), + sharedSecretProvider: new StaticSharedSecretProvider("someOtherSecret"), infoLogFunction: memoryHoleLogger, errorLogFunction: memoryHoleLogger }); - originalMerchantKeyProvider = jwtAuthorizationRoute.merchantKeyProvider; - (jwtAuthorizationRoute as any).merchantKeyProvider = staticKey = new StaticKey("someOtherSecret"); - }); - - afterEach(() => { - (jwtAuthorizationRoute as any).merchantKeyProvider = originalMerchantKeyProvider; - originalMerchantKeyProvider = staticKey = null }); it("verifies a valid merchant JWT", async() => { @@ -622,7 +611,7 @@ describe("JwtAuthorizationRoute", () => { }); it("rejects a JWT with a bad signature in the Authorization header", async() => { - (jwtAuthorizationRoute as any).merchantKeyProvider = new StaticKey("someDifferentSecret"); + (jwtAuthorizationRoute as any).sharedSecretProvider = new StaticSharedSecretProvider("someDifferentSecret"); router.route(jwtAuthorizationRoute); router.route(happyRoute); diff --git a/src/jwtauth/JwtAuthorizationRoute.ts b/src/jwtauth/JwtAuthorizationRoute.ts index 77d4f1a..691e3ef 100644 --- a/src/jwtauth/JwtAuthorizationRoute.ts +++ b/src/jwtauth/JwtAuthorizationRoute.ts @@ -5,8 +5,7 @@ import {AuthorizationHeader} from "./AuthorizationHeader"; import {AuthenticationConfig} from "../secureConfig"; import {RolesConfig} from "../secureConfig"; import {JwtPayload} from "./JwtPayload"; -import {MerchantKeyProvider} from "./merchantSharedKey/MerchantKeyProvider"; -import {RestMerchantKeyProvider} from "./merchantSharedKey/RestMerchantKeyProvider"; +import {SharedSecretProvider} from "./sharedSecret"; import {JwtAuthorizationRouteOptions} from "./JwtAuthorizationRouteOptions"; export class JwtAuthorizationRoute implements cassava.routes.Route { @@ -15,19 +14,14 @@ export class JwtAuthorizationRoute implements cassava.routes.Route { private readonly errorLogFunction?: (...msg: any[]) => void = console.error.bind(console); private readonly authConfigPromise: Promise; private readonly rolesConfigPromise?: Promise; - readonly merchantKeyProvider: MerchantKeyProvider; + private readonly sharedSecretProvider: SharedSecretProvider; constructor(private readonly options: JwtAuthorizationRouteOptions) { this.infoLogFunction = options.infoLogFunction || this.infoLogFunction; this.errorLogFunction = options.errorLogFunction || this.errorLogFunction; this.authConfigPromise = options.authConfigPromise; this.rolesConfigPromise = options.rolesConfigPromise; - - if (options.merchantKeyUri && options.assumeGetSharedSecretToken) { - this.merchantKeyProvider = new RestMerchantKeyProvider(options.merchantKeyUri, options.assumeGetSharedSecretToken); - } else if (options.merchantKeyUri || options.assumeGetSharedSecretToken) { - throw new Error("Configuration error. You must provide both the merchantKeyUri and the assumeGetSharedSecretToken or neither."); - } + this.sharedSecretProvider = options.sharedSecretProvider; } async handle(evt: cassava.RouterEvent): Promise { @@ -137,10 +131,10 @@ export class JwtAuthorizationRoute implements cassava.routes.Route { let secret: string; if (unverifiedAuthPayload.iss === "MERCHANT") { - if (!this.merchantKeyProvider) { + if (!this.sharedSecretProvider) { throw new Error("Merchant key provider has not been configured. Not accepting merchant signed tokens."); } - secret = await this.merchantKeyProvider.getMerchantKey(token); + secret = await this.sharedSecretProvider.getSharedSecret(token); if (!secret) { throw new Error("Secret is null. Check that the merchant has set a shared secret."); } diff --git a/src/jwtauth/JwtAuthorizationRouteOptions.ts b/src/jwtauth/JwtAuthorizationRouteOptions.ts index cd6e745..6fab325 100644 --- a/src/jwtauth/JwtAuthorizationRouteOptions.ts +++ b/src/jwtauth/JwtAuthorizationRouteOptions.ts @@ -1,12 +1,11 @@ import {AuthenticationConfig} from "../secureConfig"; import {RolesConfig} from "../secureConfig"; -import {AssumeScopeToken} from "../secureConfig"; +import {SharedSecretProvider} from "./sharedSecret/SharedSecretProvider"; export interface JwtAuthorizationRouteOptions { authConfigPromise: Promise; rolesConfigPromise?: Promise; - merchantKeyUri?: string; - assumeGetSharedSecretToken?: Promise; + sharedSecretProvider?: SharedSecretProvider; infoLogFunction?: (...msg: any[]) => void; errorLogFunction?: (...msg: any[]) => void; } diff --git a/src/jwtauth/index.ts b/src/jwtauth/index.ts index c6217f5..1a6d225 100644 --- a/src/jwtauth/index.ts +++ b/src/jwtauth/index.ts @@ -3,3 +3,4 @@ export {AuthorizationHeader} from "./AuthorizationHeader"; export {JwtAuthorizationRoute} from "./JwtAuthorizationRoute"; export {JwtHeader} from "./JwtHeader"; export {JwtPayload} from "./JwtPayload"; +export * from "./sharedSecret"; diff --git a/src/jwtauth/merchantSharedKey/MerchantKeyProvider.ts b/src/jwtauth/merchantSharedKey/MerchantKeyProvider.ts deleted file mode 100644 index 3063180..0000000 --- a/src/jwtauth/merchantSharedKey/MerchantKeyProvider.ts +++ /dev/null @@ -1,5 +0,0 @@ - - -export interface MerchantKeyProvider { - getMerchantKey(token: string): Promise; -} diff --git a/src/jwtauth/merchantSharedKey/StaticKey.ts b/src/jwtauth/merchantSharedKey/StaticKey.ts deleted file mode 100644 index baf0a56..0000000 --- a/src/jwtauth/merchantSharedKey/StaticKey.ts +++ /dev/null @@ -1,13 +0,0 @@ - -import {MerchantKeyProvider} from "./MerchantKeyProvider"; - -export class StaticKey implements MerchantKeyProvider { - - constructor( - private readonly key: string, - ) {} - - async getMerchantKey(token: string): Promise { - return Promise.resolve(this.key); - } -} diff --git a/src/jwtauth/merchantSharedKey/RestMerchantKeyProvider.ts b/src/jwtauth/sharedSecret/RestSharedSecretProvider.ts similarity index 53% rename from src/jwtauth/merchantSharedKey/RestMerchantKeyProvider.ts rename to src/jwtauth/sharedSecret/RestSharedSecretProvider.ts index cb3432b..2039cd6 100644 --- a/src/jwtauth/merchantSharedKey/RestMerchantKeyProvider.ts +++ b/src/jwtauth/sharedSecret/RestSharedSecretProvider.ts @@ -1,22 +1,22 @@ import * as superagent from "superagent"; import {AssumeScopeToken} from "../../secureConfig"; -import {MerchantKeyProvider} from "./MerchantKeyProvider"; +import {SharedSecretProvider} from "./SharedSecretProvider"; -export class RestMerchantKeyProvider implements MerchantKeyProvider { +export class RestSharedSecretProvider implements SharedSecretProvider { constructor( - private readonly merchantKeyUri: string, + private readonly sharedSecretUri: string, private readonly assumeGetSharedSecretToken: Promise ) { - if (!/^https?:\/\//.test(this.merchantKeyUri)) { - this.merchantKeyUri = "https://" + this.merchantKeyUri; + if (!/^https?:\/\//.test(this.sharedSecretUri)) { + this.sharedSecretUri = "https://" + this.sharedSecretUri; } } - async getMerchantKey(token: string): Promise { + async getSharedSecret(token: string): Promise { const tokenPayload = token.split(".")[1]; const storageTokenConfig = await this.assumeGetSharedSecretToken; - const resp = await superagent("GET", this.merchantKeyUri) + const resp = await superagent("GET", this.sharedSecretUri) .set("Authorization", `Bearer ${storageTokenConfig.assumeToken}`) .set("AuthorizeAs", tokenPayload); return resp.body; diff --git a/src/jwtauth/sharedSecret/SharedSecretProvider.ts b/src/jwtauth/sharedSecret/SharedSecretProvider.ts new file mode 100644 index 0000000..3fab10e --- /dev/null +++ b/src/jwtauth/sharedSecret/SharedSecretProvider.ts @@ -0,0 +1,7 @@ +export interface SharedSecretProvider { + + /** + * Get the shared secret for the given Authorization token. + */ + getSharedSecret(token: string): Promise; +} diff --git a/src/jwtauth/sharedSecret/StaticSharedSecretProvider.ts b/src/jwtauth/sharedSecret/StaticSharedSecretProvider.ts new file mode 100644 index 0000000..2e25cc4 --- /dev/null +++ b/src/jwtauth/sharedSecret/StaticSharedSecretProvider.ts @@ -0,0 +1,11 @@ +import {SharedSecretProvider} from "./SharedSecretProvider"; + +export class StaticSharedSecretProvider implements SharedSecretProvider { + + constructor(private readonly key: string) { + } + + async getSharedSecret(token: string): Promise { + return Promise.resolve(this.key); + } +} diff --git a/src/jwtauth/sharedSecret/index.ts b/src/jwtauth/sharedSecret/index.ts new file mode 100644 index 0000000..ae6cf82 --- /dev/null +++ b/src/jwtauth/sharedSecret/index.ts @@ -0,0 +1,3 @@ +export * from "./RestSharedSecretProvider"; +export * from "./SharedSecretProvider"; +export * from "./StaticSharedSecretProvider"; diff --git a/src/secureConfig/index.test.ts b/src/secureConfig/index.test.ts index ad6815c..537a794 100644 --- a/src/secureConfig/index.test.ts +++ b/src/secureConfig/index.test.ts @@ -29,7 +29,7 @@ describe("secureConfig", () => { promise: () => Promise.resolve({ Body: Buffer.from(JSON.stringify(value)) }) - } + } as aws.Request }); const result = await secureConfig.fetchFromS3("hat", "Florida"); @@ -47,7 +47,7 @@ describe("secureConfig", () => { chai.assert.equal(params.Key, "Florida"); return { promise: () => Promise.reject(new Error("I'm a network error")) - } + } as aws.Request }) .onSecondCall() .callsFake((operation: string, params: {Bucket: string, Key: string}) => { @@ -55,7 +55,7 @@ describe("secureConfig", () => { chai.assert.equal(params.Key, "Florida"); return { promise: () => Promise.reject(new Error("I'm a network error")) - } + } as aws.Request }) .onThirdCall() .callsFake((operation: string, params: {Bucket: string, Key: string}) => { @@ -65,7 +65,7 @@ describe("secureConfig", () => { promise: () => Promise.resolve({ Body: Buffer.from(JSON.stringify(value)) }) - } + } as aws.Request }); const result = await secureConfig.fetchFromS3("hat", "Florida");