Skip to content

Commit

Permalink
Merge pull request #43 from hapijs/hapi8
Browse files Browse the repository at this point in the history
Hapi8
  • Loading branch information
Eran Hammer committed Nov 28, 2014
2 parents 54d256e + 7926d01 commit a96afcc
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 117 deletions.
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load modules

var Hoek = require('hoek');
var Boom = require('boom');
var Hoek = require('hoek');
var Joi = require('joi');
var OAuth = require('./oauth');
var Providers = require('./providers');
Expand All @@ -12,9 +12,9 @@ var Providers = require('./providers');
var internals = {};


exports.register = function (plugin, options, next) {
exports.register = function (server, options, next) {

plugin.auth.scheme('bell', internals.implementation);
server.auth.scheme('bell', internals.implementation);
next();
};

Expand Down Expand Up @@ -82,7 +82,7 @@ internals.implementation = function (server, options) {
isHttpOnly: settings.isHttpOnly !== false, // Defaults to true
ttl: settings.ttl,
domain: settings.domain,
failAction: 'log',
ignoreErrors: true,
clearInvalid: true
};

Expand Down
26 changes: 17 additions & 9 deletions lib/oauth.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Load modules

var Querystring = require('querystring');
var Crypto = require('crypto');
var Url = require('url');
var Hoek = require('hoek');
var Boom = require('boom');
var Cryptiles = require('cryptiles');
var Crypto = require('crypto');
var Hoek = require('hoek');
var Wreck = require('wreck');


Expand Down Expand Up @@ -38,7 +38,7 @@ exports.v1 = function (settings) {

// Obtain temporary OAuth credentials

var oauth_callback = request.server.location(request.path, request);
var oauth_callback = internals.location(request);
return client.temporary(oauth_callback, function (err, payload) {

if (err) {
Expand Down Expand Up @@ -93,7 +93,7 @@ exports.v1 = function (settings) {
};

if (!settings.provider.profile) {
return reply(null, { credentials: credentials });
return reply.continue({ credentials: credentials });
}

// Obtain user profile
Expand All @@ -116,7 +116,7 @@ exports.v1 = function (settings) {

settings.provider.profile.call(settings, credentials, payload, get, function () {

return reply(null, { credentials: credentials });
return reply.continue({ credentials: credentials });
});
});
};
Expand All @@ -142,7 +142,7 @@ exports.v2 = function (settings) {
var query = Hoek.clone(settings.providerParams) || {};
query.client_id = settings.clientId;
query.response_type = 'code';
query.redirect_uri = request.server.location(request.path, request);
query.redirect_uri = internals.location(request);
query.state = nonce;

var scope = settings.scope || settings.provider.scope;
Expand Down Expand Up @@ -177,7 +177,7 @@ exports.v2 = function (settings) {
client_secret: settings.clientSecret,
grant_type: 'authorization_code',
code: request.query.code,
redirect_uri: request.server.location(request.path, request)
redirect_uri: internals.location(request)
};

var requestOptions = {
Expand Down Expand Up @@ -215,7 +215,7 @@ exports.v2 = function (settings) {
};

if (!settings.provider.profile) {
return reply(null, { credentials: credentials });
return reply.continue({ credentials: credentials });
}

// Obtain user profile
Expand Down Expand Up @@ -256,7 +256,7 @@ exports.v2 = function (settings) {

settings.provider.profile.call(settings, credentials, payload, get, function () {

return reply(null, { credentials: credentials });
return reply.continue({ credentials: credentials });
});
});
};
Expand Down Expand Up @@ -482,3 +482,11 @@ internals.parse = function (payload) {

return Querystring.parse(payload);
};


internals.location = function (request) {

var info = request.connection.info;
var host = request.info.host || (info.host + ':' + info.port);
return info.protocol + '://' + host + request.path;
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bell",
"description": "Third-party login plugin for hapi",
"version": "1.3.1",
"version": "2.0.0-rc1",
"repository": "git://github.com/hapijs/bell",
"main": "index",
"keywords": [
Expand All @@ -22,7 +22,7 @@
"vk"
],
"engines": {
"node": ">=0.10.30"
"node": ">=0.10.33"
},
"dependencies": {
"boom": "2.x.x",
Expand All @@ -32,10 +32,10 @@
"wreck": "5.x.x"
},
"peerDependencies": {
"hapi": ">=6.x.x"
"hapi": ">=8.x.x"
},
"devDependencies": {
"hapi": "6.x.x",
"hapi": "8.x.x",
"hawk": "2.x.x",
"lab": "5.x.x",
"code": "1.x.x"
Expand Down
24 changes: 14 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Load modules

var Bell = require('../');
var Code = require('code');
var Lab = require('lab');
var Hapi = require('hapi');
var Hoek = require('hoek');
var Bell = require('../');
var Lab = require('lab');
var Mock = require('./mock');


Expand All @@ -28,8 +28,9 @@ describe('Bell', function () {
var mock = new Mock.V1();
mock.start(function (provider) {

var server = new Hapi.Server('localhost');
server.pack.register(Bell, function (err) {
var server = new Hapi.Server();
server.connection({ host: 'localhost', port: 80 });
server.register(Bell, function (err) {

expect(err).to.not.exist();

Expand Down Expand Up @@ -79,8 +80,9 @@ describe('Bell', function () {
var mock = new Mock.V2();
mock.start(function (provider) {

var server = new Hapi.Server('localhost');
server.pack.register(Bell, function (err) {
var server = new Hapi.Server();
server.connection({ host: 'localhost', port: 80 });
server.register(Bell, function (err) {

expect(err).to.not.exist();

Expand Down Expand Up @@ -129,8 +131,9 @@ describe('Bell', function () {
var mock = new Mock.V1();
mock.start(function (provider) {

var server = new Hapi.Server('localhost');
server.pack.register(Bell, function (err) {
var server = new Hapi.Server();
server.connection({ host: 'localhost', port: 80 });
server.register(Bell, function (err) {

expect(err).to.not.exist();

Expand Down Expand Up @@ -169,8 +172,9 @@ describe('Bell', function () {
var mock = new Mock.V1();
mock.start(function (provider) {

var server = new Hapi.Server('localhost');
server.pack.register(Bell, function (err) {
var server = new Hapi.Server();
server.connection({ host: 'localhost', port: 80 });
server.register(Bell, function (err) {

expect(err).to.not.exist();

Expand Down
12 changes: 7 additions & 5 deletions test/mock.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Load modules

var Querystring = require('querystring');
var Boom = require('boom');
var Code = require('code');
var Hawk = require('hawk');
var Lab = require('lab');
var Hapi = require('hapi');
var Hawk = require('hawk');
var Hoek = require('hoek');
var Lab = require('lab');
var Wreck = require('wreck');
var Boom = require('boom');


// Declare internals
Expand All @@ -27,7 +27,8 @@ exports.V1 = internals.V1 = function (fail) {

this.tokens = {};

this.server = new Hapi.Server(0, 'localhost');
this.server = new Hapi.Server();
this.server.connection({ host: 'localhost' });
this.server.route([
{
method: 'POST',
Expand Down Expand Up @@ -143,7 +144,8 @@ exports.V2 = internals.V2 = function () {

this.codes = {};

this.server = new Hapi.Server(0, 'localhost');
this.server = new Hapi.Server();
this.server.connection({ host: 'localhost' });
this.server.route([
{
method: 'GET',
Expand Down
Loading

0 comments on commit a96afcc

Please sign in to comment.