Sha256: 584f5807456fd6de703f19c183838c159c848d6c7d1c3e75bc3e2804ff12433c

Contents?: true

Size: 1013 Bytes

Versions: 19

Compression:

Stored size: 1013 Bytes

Contents

var createServer = require('http').createServer
  , request = require('../index')
  , hawk = require('hawk')
  , assert = require('assert')
  ;

var server = createServer(function (req, resp) {
  
  var getCred = function (id, callback) {
    assert.equal(id, 'dh37fgj492je')
    var credentials = 
      { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn'
      , algorithm: 'sha256'
      , user: 'Steve'
      }
    return callback(null, credentials)
  }

  hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) {
    resp.writeHead(!err ? 200 : 401, { 'Content-Type': 'text/plain' })
    resp.end(!err ? 'Hello ' + credentials.user : 'Shoosh!')
  })
  
})

server.listen(8080, function () {
  var creds = {key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', id:'dh37fgj492je'}
  request('http://localhost:8080', {hawk:{credentials:creds}}, function (e, r, b) {
    assert.equal(200, r.statusCode)
    assert.equal(b, 'Hello Steve')
    server.close()
  })
})

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/request/tests/test-hawk.js
ela-4.1.5 node_modules/request/tests/test-hawk.js
ela-4.1.4 node_modules/request/tests/test-hawk.js
ela-4.1.3 node_modules/request/tests/test-hawk.js
ela-4.1.2 node_modules/request/tests/test-hawk.js
ela-4.1.1 node_modules/request/tests/test-hawk.js
ela-4.1.0 node_modules/request/tests/test-hawk.js
ela-4.0.0 node_modules/request/tests/test-hawk.js
ela-3.4.3 node_modules/request/tests/test-hawk.js
ela-3.4.2 node_modules/request/tests/test-hawk.js
ela-3.4.0 node_modules/request/tests/test-hawk.js
ela-3.3.1 node_modules/request/tests/test-hawk.js
ela-3.3.0 node_modules/request/tests/test-hawk.js
ela-3.2.0 node_modules/request/tests/test-hawk.js
ela-3.1.1 node_modules/request/tests/test-hawk.js
ela-3.1.0 node_modules/request/tests/test-hawk.js
ela-3.0.0 node_modules/request/tests/test-hawk.js
ela-2.0.0 node_modules/request/tests/test-hawk.js
ela-1.1.0 node_modules/request/tests/test-hawk.js