UNPKG

hapi

Version:

HTTP Server framework

36 lines (22 loc) 1.07 kB
// Load modules var Hawk = require('hawk'); var Utils = require('../utils'); var Boom = require('boom'); // Declare internals var internals = {}; exports = module.exports = internals.Scheme = function (server, options) { Utils.assert(this.constructor === internals.Scheme, 'Scheme must be instantiated using new'); Utils.assert(options, 'Invalid options'); Utils.assert(options.scheme === 'bewit', 'Wrong scheme'); Utils.assert(options.getCredentialsFunc, 'Missing required getCredentialsFunc method in configuration'); Utils.assert(server, 'Server is required'); this.settings = Utils.clone(options); this.settings.hostHeaderName = this.settings.hostHeaderName || 'host'; return this; }; // Hawk Authentication internals.Scheme.prototype.authenticate = function (request, callback) { Hawk.uri.authenticate(request.raw.req, this.settings.getCredentialsFunc, { hostHeaderName: this.settings.hostHeaderName }, function (err, credentials, bewit) { return callback(err, credentials, { artifacts: bewit }); }); };