Comparing version 3.0.7 to 3.0.8
{ | ||
"name": "edgegrid", | ||
"version": "3.0.7", | ||
"version": "3.0.8", | ||
"description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,11 +21,11 @@ // Copyright 2014 Akamai Technologies, Inc. All Rights Reserved | ||
module.exports = { | ||
createTimestamp: function() { | ||
createTimestamp: function () { | ||
return moment().utc().format('YYYYMMDDTHH:mm:ss+0000'); | ||
}, | ||
contentHash: function(request, maxBody) { | ||
contentHash: function (request, maxBody) { | ||
var contentHash = '', | ||
preparedBody = request.body || '', | ||
isTarball = preparedBody instanceof Uint8Array && request.headers['Content-Type'] === 'application/gzip'; | ||
if (typeof preparedBody === 'object' && !isTarball) { | ||
@@ -50,19 +50,14 @@ var postDataNew = '', | ||
logger.debug('PREPARED BODY LENGTH', preparedBody.length); | ||
if (request.method === 'POST' && preparedBody.length > 0) { | ||
if (isTarball) { | ||
preparedBody = preparedBody.toString().length > maxBody ? preparedBody.toString().substring(0, maxBody) : preparedBody.toString(); | ||
logger.info('Signing content: \"' + preparedBody + '\"'); | ||
// If body data is too large, cut down to max-body size | ||
if (preparedBody.length > maxBody) { | ||
logger.warn('Data length (' + preparedBody.length + ') is larger than maximum ' + maxBody); | ||
preparedBody = preparedBody.substring(0, maxBody); | ||
logger.info('Body truncated. New value \"' + preparedBody + '\"'); | ||
} | ||
else { | ||
logger.info('Signing content: \"' + preparedBody + '\"'); | ||
// If body data is too large, cut down to max-body size | ||
if (preparedBody.length > maxBody) { | ||
logger.warn('Data length (' + preparedBody.length + ') is larger than maximum ' + maxBody); | ||
preparedBody = preparedBody.substring(0, maxBody); | ||
logger.info('Body truncated. New value \"' + preparedBody + '\"'); | ||
} | ||
} | ||
logger.debug('PREPARED BODY', preparedBody); | ||
@@ -73,7 +68,7 @@ | ||
} | ||
return contentHash; | ||
}, | ||
dataToSign: function(request, authHeader, maxBody) { | ||
dataToSign: function (request, authHeader, maxBody) { | ||
var parsedUrl = url.parse(request.url, true), | ||
@@ -97,3 +92,3 @@ dataToSign = [ | ||
extend: function(a, b) { | ||
extend: function (a, b) { | ||
var key; | ||
@@ -110,3 +105,3 @@ | ||
isRedirect: function(statusCode) { | ||
isRedirect: function (statusCode) { | ||
return [ | ||
@@ -117,3 +112,3 @@ 300, 301, 302, 303, 307 | ||
base64Sha256: function(data) { | ||
base64Sha256: function (data) { | ||
var shasum = crypto.createHash('sha256').update(data); | ||
@@ -124,3 +119,3 @@ | ||
base64HmacSha256: function(data, key) { | ||
base64HmacSha256: function (data, key) { | ||
var encrypt = crypto.createHmac('sha256', key); | ||
@@ -138,3 +133,3 @@ | ||
*/ | ||
canonicalizeHeaders: function(headers) { | ||
canonicalizeHeaders: function (headers) { | ||
var formattedHeaders = [], | ||
@@ -150,3 +145,3 @@ key; | ||
signingKey: function(timestamp, clientSecret) { | ||
signingKey: function (timestamp, clientSecret) { | ||
var key = this.base64HmacSha256(timestamp, clientSecret); | ||
@@ -159,5 +154,5 @@ | ||
signRequest: function(request, timestamp, clientSecret, authHeader, maxBody) { | ||
signRequest: function (request, timestamp, clientSecret, authHeader, maxBody) { | ||
return this.base64HmacSha256(this.dataToSign(request, authHeader, maxBody), this.signingKey(timestamp, clientSecret)); | ||
} | ||
}; |
278883
1265