diff --git a/lib/index.js b/lib/index.js index 49f406b..4884a1b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,7 +23,11 @@ function apiKeyAuth(options) { if (!options || !options.getSecret) { throw new Error('The method "getSecret" must be defined'); } - const { getSecret, requestLifetime = 300, requestProperty = 'credentials' } = options; + /* Check if "requiredHeaders" param not exists use the date HTTP header by default */ + if (typeof options.requiredHeaders!=="undefined" && !Array.isArray(options.requiredHeaders)) { + throw new Error('The object "requiredHeaders" must be a type of string[]'); + } + const { getSecret, requestLifetime = 300, requestProperty = 'credentials', requiredHeaders=['date'] } = options; const middleware = function middleware(req, res, next) { /* Don't check the signature for preflight request */ @@ -41,7 +45,8 @@ function apiKeyAuth(options) { try { signatureParams = parser.parseRequest(req, { algorithms: availableAlgorithms, - requestLifetime + requestLifetime, + requiredHeaders }); } catch (err) { return next(err);