Skip to content

Update index.js #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -41,7 +45,8 @@ function apiKeyAuth(options) {
try {
signatureParams = parser.parseRequest(req, {
algorithms: availableAlgorithms,
requestLifetime
requestLifetime,
requiredHeaders
});
} catch (err) {
return next(err);
Expand Down