Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
artifacts.hash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
}
const mac = Crypto.calculateMac('response', credentials, artifacts);
// Construct header
let header = 'Hawk mac="' + mac + '"' +
(artifacts.hash ? ', hash="' + artifacts.hash + '"' : '');
if (artifacts.ext !== null &&
artifacts.ext !== undefined &&
artifacts.ext !== '') { // Other falsey values allowed
header = header + ', ext="' + Hoek.escapeHeaderAttribute(artifacts.ext) + '"';
}
return header;
};
return err;
}
// function (message, scheme, attributes)
let wwwAuthenticate = `${scheme} `;
if (attributes ||
message) {
err.output.payload.attributes = {};
}
if (attributes) {
if (typeof attributes === 'string') {
wwwAuthenticate += Hoek.escapeHeaderAttribute(attributes);
err.output.payload.attributes = attributes;
}
else {
wwwAuthenticate += Object.keys(attributes).map((name) => {
let value = attributes[name];
if (value === null ||
value === undefined) {
value = '';
}
err.output.payload.attributes[name] = value;
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
})
.join(', ');
if (!artifacts.hash &&
(options.payload || options.payload === '')) {
artifacts.hash = Crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
}
const mac = Crypto.calculateMac('header', credentials, artifacts);
// Construct header
const hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''; // Other falsey values allowed
let header = 'Hawk id="' + credentials.id +
'", ts="' + artifacts.ts +
'", nonce="' + artifacts.nonce +
(artifacts.hash ? '", hash="' + artifacts.hash : '') +
(hasExt ? '", ext="' + Hoek.escapeHeaderAttribute(artifacts.ext) : '') +
'", mac="' + mac + '"';
if (artifacts.app) {
header = header + ', app="' + artifacts.app +
(artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"';
}
return { header, artifacts };
};
value = '';
}
err.output.payload.attributes[name] = value;
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
})
.join(', ');
}
}
if (message) {
if (attributes) {
wwwAuthenticate += ', ';
}
wwwAuthenticate += `error="${Hoek.escapeHeaderAttribute(message)}"`;
err.output.payload.attributes.error = message;
}
else {
err.isMissing = true;
}
err.output.headers['WWW-Authenticate'] = wwwAuthenticate;
return err;
};
wwwAuthenticate += Object.keys(attributes).map((name) => {
let value = attributes[name];
if (value === null ||
value === undefined) {
value = '';
}
err.output.payload.attributes[name] = value;
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
})
.join(', ');