Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
joi 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Mar 9, 2013
1 parent 2d1e69f commit 8119111
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
80 changes: 38 additions & 42 deletions lib/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand All @@ -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);
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oz",
"description": "Web Authorization Protocol",
"version": "0.1.1",
"version": "0.1.2",
"author": "Eran Hammer <[email protected]> (http://hueniverse.com)",
"contributors":[
"Wyatt Preul <[email protected]>",
Expand All @@ -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",
Expand Down

0 comments on commit 8119111

Please sign in to comment.