From a3dd471e744ca3f42d46b976b6edf1f598942996 Mon Sep 17 00:00:00 2001 From: Luis Britos Manriquez Date: Mon, 20 Apr 2020 11:19:44 -0300 Subject: [PATCH 1/4] adding headers to managementApi options --- package.json | 2 +- src/middlewares/managementApiClient.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e7e3e3b..2256ecd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A set of tools and utilities to simplify the development of Auth0 Extensions with Express.", "main": "src/index.js", "dependencies": { - "auth0-extension-tools": "^1.4.5", + "auth0-extension-tools": "^1.5.0", "cookie-parser": "^1.4.3", "express": "^4.17.1", "express-conditional-middleware": "2.0.0", diff --git a/src/middlewares/managementApiClient.js b/src/middlewares/managementApiClient.js index a09a09b..bca06ce 100644 --- a/src/middlewares/managementApiClient.js +++ b/src/middlewares/managementApiClient.js @@ -6,7 +6,8 @@ module.exports = function(handlerOptions) { const isAdministrator = req.user && req.user.access_token && req.user.access_token.length; const options = !isAdministrator ? handlerOptions : { domain: handlerOptions.domain, - accessToken: req.user.access_token + accessToken: req.user.access_token, + headers: handlerOptions.headers }; tools.managementApi.getClient(options) From f6dd33b4f79079e060b328e9c5a89dc8401f904f Mon Sep 17 00:00:00 2001 From: Luis Britos Manriquez Date: Mon, 20 Apr 2020 11:20:12 -0300 Subject: [PATCH 2/4] 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2256ecd..4caa194 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-extension-express-tools", - "version": "2.0.1", + "version": "2.1.0", "description": "A set of tools and utilities to simplify the development of Auth0 Extensions with Express.", "main": "src/index.js", "dependencies": { From cd9ec515d50d8bea30d80d0c72cf2dfd3424b2c2 Mon Sep 17 00:00:00 2001 From: Luis Britos Manriquez Date: Mon, 20 Apr 2020 15:01:40 -0300 Subject: [PATCH 3/4] adding test --- tests/middlewares/managementApiClient.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/middlewares/managementApiClient.js b/tests/middlewares/managementApiClient.js index e41697e..d6612c8 100644 --- a/tests/middlewares/managementApiClient.js +++ b/tests/middlewares/managementApiClient.js @@ -38,3 +38,23 @@ tape('managementApiClient errors should bubble up in the middleware', function(t t.end(); }); }); + +tape('managementApiClient should attach client to the request with headers', function(t) { + const options = { + domain: 'me.auth0.com', + accessToken: 'ey', + headers: { customHeader: 'custom' } + }; + + const mw = managementApiClientMiddleware(options); + t.ok(mw); + + const req = { }; + mw(req, { }, function() { + t.ok(req); + t.ok(req.auth0); + const keys = Object.keys(req.auth0); + keys.forEach(key => req.auth0[key].resource && t.equal(req.auth0[key].resource.restClient.options.headers.customHeader, 'custom')); + t.end(); + }); +}); From fe09ef3988e0ff9a03546605b009fa475d8e0ef7 Mon Sep 17 00:00:00 2001 From: Luis Britos Manriquez Date: Mon, 20 Apr 2020 17:26:15 -0300 Subject: [PATCH 4/4] fix tests --- tests/routes/dashboardAdmins.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/routes/dashboardAdmins.js b/tests/routes/dashboardAdmins.js index 7145010..1cc06ef 100644 --- a/tests/routes/dashboardAdmins.js +++ b/tests/routes/dashboardAdmins.js @@ -397,7 +397,8 @@ tape('dashboardAdmins should return 200 if everything is ok', function(t) { azp: 'https://test.auth0.com/api/v2/', name: 'John Doe', admin: true, - nonce: 'nonce' + nonce: 'nonce', + exp: new Date().getTime() }); const req = { @@ -455,7 +456,8 @@ tape('dashboardAdmins should return 200 with legacy nonce and state', function(t azp: 'https://test.auth0.com/api/v2/', name: 'John Doe', admin: true, - nonce: 'nonce' + nonce: 'nonce', + exp: new Date().getTime() }); const req = { @@ -514,7 +516,8 @@ tape('dashboardAdmins should work with localStorage', function(t) { azp: 'https://test.auth0.com/api/v2/', name: 'John Doe', admin: true, - nonce: 'nonce' + nonce: 'nonce', + exp: new Date().getTime() }); const req = {