Skip to content

Commit

Permalink
Merge pull request #26 from auth0-extensions/DXEX-508-allow-set-custo…
Browse files Browse the repository at this point in the history
…m-headers-auth0-managementClient

DXEX-508 adding headers to managementApi options
  • Loading branch information
luisbritos committed Apr 22, 2020
2 parents e5281fc + fe09ef3 commit fa8bff2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"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": {
"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",
Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/managementApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/middlewares/managementApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
9 changes: 6 additions & 3 deletions tests/routes/dashboardAdmins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit fa8bff2

Please sign in to comment.