From 8119111f5289f1fc64749fc39074797744ea9f87 Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Fri, 8 Mar 2013 20:54:07 -0800 Subject: [PATCH] joi 0.2 --- lib/endpoints.js | 80 +++++++++++++++++++++++------------------------- package.json | 8 ++--- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/lib/endpoints.js b/lib/endpoints.js index b2f201c..19a515c 100755 --- a/lib/endpoints.js +++ b/lib/endpoints.js @@ -118,20 +118,18 @@ exports.reissue = function (req, payload, options, callback) { Ticket.reissue(ticket, options.encryptionPassword, ticketOptions, callback); }; - Joi.validate(payload, schema, function (err) { + var error = Joi.validate(payload, schema); + if (error) { + return callback(Boom.badRequest(error.message)); + } + + internals.authenticate(req, 'any', options, function (err, ticket) { if (err) { - return callback(Boom.badRequest(err.message)); + return callback(err); } - internals.authenticate(req, 'any', options, function (err, ticket) { - - if (err) { - return callback(err); - } - - load(ticket); - }); + load(ticket); }); }; @@ -142,57 +140,55 @@ exports.rsvp = function (req, payload, options, callback) { rsvp: Joi.Types.String().required() }; - Joi.validate(payload, schema, function (err) { + var error = Joi.validate(payload, schema); + if (error) { + return callback(Boom.badRequest(error.message)); + } + + internals.authenticate(req, 'app', options, function (err, ticket) { if (err) { - return callback(Boom.badRequest(err.message)); + return callback(err); } - internals.authenticate(req, 'app', options, function (err, ticket) { + Rsvp.parse(payload.rsvp, options.encryptionPassword, function (err, envelope) { if (err) { return callback(err); } - Rsvp.parse(payload.rsvp, options.encryptionPassword, function (err, envelope) { + if (envelope.app !== ticket.app) { + return callback(Boom.forbidden('Mismatching ticket and rsvp apps')); + } - if (err) { - return callback(err); - } + var now = Date.now(); - if (envelope.app !== ticket.app) { - return callback(Boom.forbidden('Mismatching ticket and rsvp apps')); - } + if (envelope.exp <= now) { + return callback(Boom.forbidden('Expired rsvp')); + } - var now = Date.now(); + options.loadGrantFunc(envelope.grant, function (grant, ext) { - if (envelope.exp <= now) { - return callback(Boom.forbidden('Expired rsvp')); - } + if (!grant || + grant.app !== ticket.app || + !grant.exp || + grant.exp <= now) { - options.loadGrantFunc(envelope.grant, function (grant, ext) { + return callback(Boom.forbidden('Invalid grant')); + } - if (!grant || - grant.app !== ticket.app || - !grant.exp || - grant.exp <= now) { + options.loadAppFunc(grant.app, function (app) { - return callback(Boom.forbidden('Invalid grant')); + if (!app) { + return callback(Boom.forbidden('Invalid application identifier or secret')); } - options.loadAppFunc(grant.app, function (app) { - - if (!app) { - return callback(Boom.forbidden('Invalid application identifier or secret')); - } - - var ticketOptions = {}; - if (ext) { - ticketOptions.ext = ext; - } + var ticketOptions = {}; + if (ext) { + ticketOptions.ext = ext; + } - Ticket.issue(app, grant, options.encryptionPassword, ticketOptions, callback); - }); + Ticket.issue(app, grant, options.encryptionPassword, ticketOptions, callback); }); }); }); diff --git a/package.json b/package.json index bba42de..044b690 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "oz", "description": "Web Authorization Protocol", - "version": "0.1.1", + "version": "0.1.2", "author": "Eran Hammer (http://hueniverse.com)", "contributors":[ "Wyatt Preul ", @@ -18,12 +18,12 @@ "node": "0.8.x" }, "dependencies": { - "joi": "0.1.x", - "hoek": "0.4.x", + "joi": "0.2.x", + "hoek": "0.6.x", "boom": "0.3.x", "iron": "0.2.x", "cryptiles": "0.1.x", - "hawk": "0.7.x" + "hawk": "0.10.x" }, "devDependencies": { "mocha": "1.x.x",