oauth2orize
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -188,3 +188,30 @@ /** | ||
function errorHandler(err, txn, res, next) { | ||
var mode = 'query' | ||
, params = {} | ||
, respond; | ||
if (txn.req && txn.req.responseMode) { | ||
mode = txn.req.responseMode; | ||
} | ||
respond = modes[mode]; | ||
if (!respond) { | ||
return next(err); | ||
} | ||
if (respond && respond.validate) { | ||
try { | ||
respond.validate(txn); | ||
} catch(ex) { | ||
return next(err); | ||
} | ||
} | ||
params.error = err.code || 'server_error'; | ||
if (err.message) { params.error_description = err.message; } | ||
if (err.uri) { params.error_uri = err.uri; } | ||
if (txn.req && txn.req.state) { params.state = txn.req.state; } | ||
return respond(txn, res, params); | ||
} | ||
/** | ||
@@ -197,3 +224,4 @@ * Return `code` approval module. | ||
mod.response = response; | ||
mod.error = errorHandler; | ||
return mod; | ||
}; |
@@ -190,3 +190,30 @@ /** | ||
function errorHandler(err, txn, res, next) { | ||
var mode = 'fragment' | ||
, params = {} | ||
, respond; | ||
if (txn.req && txn.req.responseMode) { | ||
mode = txn.req.responseMode; | ||
} | ||
respond = modes[mode]; | ||
if (!respond) { | ||
return next(err); | ||
} | ||
if (respond && respond.validate) { | ||
try { | ||
respond.validate(txn); | ||
} catch(ex) { | ||
return next(err); | ||
} | ||
} | ||
params.error = err.code || 'server_error'; | ||
if (err.message) { params.error_description = err.message; } | ||
if (err.uri) { params.error_uri = err.uri; } | ||
if (txn.req && txn.req.state) { params.state = txn.req.state; } | ||
return respond(txn, res, params); | ||
} | ||
/** | ||
@@ -199,3 +226,4 @@ * Return `token` approval module. | ||
mod.response = response; | ||
mod.error = errorHandler; | ||
return mod; | ||
}; |
@@ -130,2 +130,4 @@ /** | ||
if (redirectURI) { req.oauth2.redirectURI = redirectURI; } | ||
req.oauth2.req = areq; | ||
req.oauth2.user = req[userProperty]; | ||
@@ -135,5 +137,2 @@ if (err) { return next(err); } | ||
req.oauth2.req = areq; | ||
req.oauth2.user = req[userProperty]; | ||
function immediated(err, allow, info, locals) { | ||
@@ -140,0 +139,0 @@ if (err) { return next(err); } |
@@ -112,2 +112,3 @@ /** | ||
}; | ||
req.oauth2._endProxied = true; | ||
@@ -114,0 +115,0 @@ server._respond(req.oauth2, res, function(err) { |
@@ -49,2 +49,3 @@ /** | ||
}; | ||
req.oauth2._endProxied = true; | ||
@@ -51,0 +52,0 @@ server._respond(req.oauth2, res, function(err) { |
@@ -33,2 +33,4 @@ /** | ||
return function transactionLoader(req, res, next) { | ||
if (req.oauth2) { return next(); } | ||
function loaded(err, txn) { | ||
@@ -35,0 +37,0 @@ if (err) { return next(err); } |
@@ -11,2 +11,3 @@ /** | ||
, token = require('./middleware/token') | ||
, authorizationErrorHandler = require('./middleware/authorizationErrorHandler') | ||
, errorHandler = require('./middleware/errorHandler') | ||
@@ -26,2 +27,3 @@ , utils = require('./utils') | ||
this._resHandlers = []; | ||
this._errHandlers = []; | ||
this._exchanges = []; | ||
@@ -66,2 +68,3 @@ | ||
if (mod.response) { this.grant(mod.name, 'response', mod.response); } | ||
if (mod.error) { this.grant(mod.name, 'error', mod.error); } | ||
return this; | ||
@@ -74,2 +77,3 @@ } | ||
if (mod.response) { this.grant(type, 'response', mod.response); } | ||
if (mod.error) { this.grant(type, 'error', mod.error); } | ||
return this; | ||
@@ -92,2 +96,5 @@ } | ||
this._resHandlers.push({ type: type, handle: fn }); | ||
} else if (phase == 'error') { | ||
debug('register error handler %s %s', type || '*', fn.name || 'anonymous'); | ||
this._errHandlers.push({ type: type, handle: fn }); | ||
} | ||
@@ -157,2 +164,17 @@ return this; | ||
Server.prototype.authorizeError = | ||
Server.prototype.authorizationError = | ||
Server.prototype.authorizationErrorHandler = function(options) { | ||
var loader = transactionLoader(this, options); | ||
return [ | ||
function transactionLoaderErrorWrapper(err, req, res, next) { | ||
loader(req, res, function(ierr) { | ||
return next(err); | ||
}); | ||
}, | ||
authorizationErrorHandler(this, options) | ||
]; | ||
}; | ||
/** | ||
@@ -338,2 +360,25 @@ * Handle requests to exchange an authorization grant for an access token. | ||
Server.prototype._respondError = function(err, txn, res, cb) { | ||
var ultype = new UnorderedList(txn.req.type) | ||
, stack = this._errHandlers | ||
, idx = 0; | ||
function next(err) { | ||
var layer = stack[idx++]; | ||
if (!layer) { return cb(err); } | ||
try { | ||
debug('error:%s', layer.handle.name || 'anonymous'); | ||
if (layer.type === null || layer.type.equalTo(ultype)) { | ||
layer.handle(err, txn, res, next); | ||
} else { | ||
next(err); | ||
} | ||
} catch (ex) { | ||
return cb(ex); | ||
} | ||
} | ||
next(err); | ||
} | ||
/** | ||
@@ -340,0 +385,0 @@ * Process token request using registered exchange middleware. |
{ | ||
"name": "oauth2orize", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "OAuth 2.0 authorization server toolkit for Node.js.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90919
29
2227