Skip to content

Commit a73895b

Browse files
author
Eric Lambrecht
committed
add SHA-256 support
1 parent a0f8d20 commit a73895b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/passport-http-oauth/strategies/consumer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ ConsumerStrategy.prototype.authenticate = function(req) {
293293
if (tokenSecret) { key += utils.encode(tokenSecret); }
294294
var computedSignature = utils.hmacsha1(key, base);
295295

296+
if (signature !== computedSignature) {
297+
return self.fail(self._challenge('signature_invalid'));
298+
}
299+
300+
} else if (signatureMethod === 'HMAC-SHA256') {
301+
var key = consumerSecret + '&';
302+
if (tokenSecret) { key += tokenSecret; }
303+
var computedSignature = utils.hmacsha256(key, base);
304+
296305
if (signature !== computedSignature) {
297306
return self.fail(self._challenge('signature_invalid'));
298307
}

lib/passport-http-oauth/strategies/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ exports.hmacsha1 = function(key, text) {
185185
return crypto.createHmac('sha1', key).update(text).digest('base64')
186186
}
187187

188+
/**
189+
* Generate HMAC-SHA256 signature.
190+
*
191+
* @param {String} key
192+
* @param {String} text
193+
* @return {String}
194+
* @api private
195+
*/
196+
exports.hmacsha256 = function(key, text) {
197+
return crypto.createHmac('sha256', key).update(text).digest('base64')
198+
}
199+
188200
/**
189201
* Generate PLAINTEXT signature.
190202
*

0 commit comments

Comments
 (0)