From f04be78a35173276ee118b2ee7f3e411de2a4d9d Mon Sep 17 00:00:00 2001 From: kornel-kedzierski Date: Fri, 23 Feb 2018 11:53:49 +0100 Subject: [PATCH] Update hawk to 7.0.7 --- package.json | 2 +- request.js | 2 +- tests/test-hawk.js | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 58090fa22..a1dce8e31 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "forever-agent": "~0.6.1", "form-data": "~2.3.1", "har-validator": "~5.0.3", - "hawk": "~6.0.2", + "hawk": "~7.0.7", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", diff --git a/request.js b/request.js index ff19ca39c..404c859d2 100644 --- a/request.js +++ b/request.js @@ -1426,7 +1426,7 @@ Request.prototype.httpSignature = function (opts) { } Request.prototype.hawk = function (opts) { var self = this - self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).field) + self.setHeader('Authorization', hawk.client.header(self.uri, self.method, opts).header) } Request.prototype.oauth = function (_oauth) { var self = this diff --git a/tests/test-hawk.js b/tests/test-hawk.js index 34db8da25..19aab5d7d 100644 --- a/tests/test-hawk.js +++ b/tests/test-hawk.js @@ -7,22 +7,24 @@ var tape = require('tape') var assert = require('assert') var server = http.createServer(function (req, res) { - var getCred = function (id, callback) { + var getCred = function (id) { assert.equal(id, 'dh37fgj492je') var credentials = { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', user: 'Steve' } - return callback(null, credentials) + return credentials } - - hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) { - res.writeHead(err ? 401 : 200, { - 'Content-Type': 'text/plain' + hawk.server.authenticate(req, getCred) + .then((credentials, artifacts) => { + res.writeHead(200, {'Content-Type': 'text/plain'}) + res.end('Hello ' + credentials.credentials.user) + }) + .catch(() => { + res.writeHead(401, {'Content-Type': 'text/plain'}) + res.end('Shoosh!') }) - res.end(err ? 'Shoosh!' : 'Hello ' + credentials.user) - }) }) tape('setup', function (t) {