Created
October 28, 2015 23:23
-
-
Save ixti/881e6f63546b244d605b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/config/default.yml b/config/default.yml | |
| index d47f235..6440416 100644 | |
| --- a/config/default.yml | |
| +++ b/config/default.yml | |
| @@ -18,6 +18,8 @@ gatekeeper: | |
| host: 127.0.0.1 | |
| starting_port: 4000 | |
| target: "127.0.0.1:6081" | |
| + api_key_header_name: "x-api-key" | |
| + api_key_param_name: "api_key" | |
| api_key_methods: | |
| - header | |
| - getParam | |
| diff --git a/lib/gatekeeper/middleware/api_key_validator.js b/lib/gatekeeper/middleware/api_key_validator.js | |
| index 68f3f91..81c78c0 100644 | |
| --- a/lib/gatekeeper/middleware/api_key_validator.js | |
| +++ b/lib/gatekeeper/middleware/api_key_validator.js | |
| @@ -70,13 +70,16 @@ _.extend(ApiKeyValidatorRequest.prototype, { | |
| resolveApiKey: function() { | |
| var apiKey; | |
| + var headerName = config.get('gatekeeper.api_key_header_name'); | |
| + var paramName = config.get('gatekeeper.api_key_param_name'); | |
| + | |
| for(var i = 0, len = this.validator.apiKeyMethods.length; i < len; i++) { | |
| switch(this.validator.apiKeyMethods[i]) { | |
| case 'header': | |
| - apiKey = this.request.headers['x-api-key']; | |
| + apiKey = this.request.headers[headerName]; | |
| break; | |
| case 'getParam': | |
| - apiKey = this.request.query.api_key; | |
| + apiKey = this.request.query[paramName]; | |
| break; | |
| case 'basicAuthUsername': | |
| apiKey = this.request.basicAuthUsername; | |
| diff --git a/lib/gatekeeper/middleware/rewrite_response.js b/lib/gatekeeper/middleware/rewrite_response.js | |
| index 8fc8422..770afaa 100644 | |
| --- a/lib/gatekeeper/middleware/rewrite_response.js | |
| +++ b/lib/gatekeeper/middleware/rewrite_response.js | |
| @@ -1,7 +1,8 @@ | |
| 'use strict'; | |
| var _ = require('lodash'), | |
| - url = require('url'); | |
| + url = require('url'), | |
| + config = require('api-umbrella-config').global(); | |
| var RewriteResponse = function() { | |
| this.initialize.apply(this, arguments); | |
| @@ -49,7 +50,7 @@ _.extend(RewriteResponse.prototype, { | |
| } | |
| if (apiKey && hasBeenModified) { | |
| loc.query = loc.query || {}; | |
| - loc.query['api_key'] = apiKey; // overrides | |
| + loc.query[config.get('gatekeeper.api_key_param_name')] = apiKey; // overrides | |
| delete loc.search; // make sure loc.query is used | |
| } | |
| response.setHeader('location', url.format(loc)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment