oauth2orize
Advanced tools
Comparing version 1.0.1 to 1.1.0
/** | ||
* Module dependencies. | ||
*/ | ||
var OAuth2Error = require('./oauth2error'); | ||
/** | ||
* `AuthorizationError` error. | ||
@@ -18,15 +23,11 @@ * | ||
Error.call(this); | ||
OAuth2Error.call(this, message, code, uri, status); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.name = 'AuthorizationError'; | ||
this.message = message; | ||
this.code = code || 'server_error'; | ||
this.uri = uri; | ||
this.status = status || 500; | ||
} | ||
/** | ||
* Inherit from `Error`. | ||
* Inherit from `OAuth2Error`. | ||
*/ | ||
AuthorizationError.prototype.__proto__ = Error.prototype; | ||
AuthorizationError.prototype.__proto__ = OAuth2Error.prototype; | ||
@@ -33,0 +34,0 @@ |
/** | ||
* Module dependencies. | ||
*/ | ||
var OAuth2Error = require('./oauth2error'); | ||
/** | ||
* `TokenError` error. | ||
@@ -18,15 +23,11 @@ * | ||
Error.call(this); | ||
OAuth2Error.call(this, message, code, uri, status); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.name = 'TokenError'; | ||
this.message = message; | ||
this.code = code || 'server_error'; | ||
this.uri = uri; | ||
this.status = status || 500; | ||
} | ||
/** | ||
* Inherit from `Error`. | ||
* Inherit from `OAuth2Error`. | ||
*/ | ||
TokenError.prototype.__proto__ = Error.prototype; | ||
TokenError.prototype.__proto__ = OAuth2Error.prototype; | ||
@@ -33,0 +34,0 @@ |
@@ -80,23 +80,30 @@ /** | ||
function issued(err, accessToken, refreshToken, params) { | ||
if (err) { return next(err); } | ||
if (!accessToken) { return next(new TokenError('Invalid authorization code', 'invalid_grant')); } | ||
if (refreshToken && typeof refreshToken == 'object') { | ||
params = refreshToken; | ||
refreshToken = null; | ||
} | ||
var tok = {}; | ||
tok.access_token = accessToken; | ||
if (refreshToken) { tok.refresh_token = refreshToken; } | ||
if (params) { utils.merge(tok, params); } | ||
tok.token_type = tok.token_type || 'Bearer'; | ||
var json = JSON.stringify(tok); | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.setHeader('Cache-Control', 'no-store'); | ||
res.setHeader('Pragma', 'no-cache'); | ||
res.end(json); | ||
} | ||
try { | ||
issue(client, code, redirectURI, function(err, accessToken, refreshToken, params) { | ||
if (err) { return next(err); } | ||
if (!accessToken) { return next(new TokenError('Invalid authorization code', 'invalid_grant')); } | ||
if (refreshToken && typeof refreshToken == 'object') { | ||
params = refreshToken; | ||
refreshToken = null; | ||
} | ||
var tok = {}; | ||
tok.access_token = accessToken; | ||
if (refreshToken) { tok.refresh_token = refreshToken; } | ||
if (params) { utils.merge(tok, params); } | ||
tok.token_type = tok.token_type || 'Bearer'; | ||
var json = JSON.stringify(tok); | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.setHeader('Cache-Control', 'no-store'); | ||
res.setHeader('Pragma', 'no-cache'); | ||
res.end(json); | ||
}); | ||
var arity = issue.length; | ||
if (arity == 5) { | ||
issue(client, code, redirectURI, req.body, issued); | ||
} else { // arity == 4 | ||
issue(client, code, redirectURI, issued); | ||
} | ||
} catch (ex) { | ||
@@ -103,0 +110,0 @@ return next(ex); |
@@ -122,3 +122,5 @@ /** | ||
var arity = issue.length; | ||
if (arity == 3) { | ||
if (arity == 4) { | ||
issue(client, scope, req.body, issued); | ||
} else if (arity == 3) { | ||
issue(client, scope, issued); | ||
@@ -125,0 +127,0 @@ } else { // arity == 2 |
@@ -128,3 +128,5 @@ /** | ||
var arity = issue.length; | ||
if (arity == 5) { | ||
if (arity == 6) { | ||
issue(client, username, passwd, scope, req.body, issued); | ||
} else if (arity == 5) { | ||
issue(client, username, passwd, scope, issued); | ||
@@ -131,0 +133,0 @@ } else { // arity == 4 |
@@ -155,3 +155,5 @@ /** | ||
var arity = issue.length; | ||
if (arity == 5) { | ||
if (arity == 6) { | ||
issue(txn.client, txn.req.redirectURI, txn.user, txn.res, txn.req, issued); | ||
} else if (arity == 5) { | ||
issue(txn.client, txn.req.redirectURI, txn.user, txn.res, issued); | ||
@@ -158,0 +160,0 @@ } else { // arity == 4 |
@@ -42,3 +42,3 @@ /** | ||
var name = path.basename(filename, '.js'); | ||
function load() { return require('./grant/' + name); } | ||
var load = function () { return require('./grant/' + name); }; | ||
exports.grant.__defineGetter__(name, load); | ||
@@ -60,3 +60,3 @@ } | ||
var name = path.basename(filename, '.js'); | ||
function load() { return require('./exchange/' + name); } | ||
var load = function () { return require('./exchange/' + name); }; | ||
exports.exchange.__defineGetter__(name, load); | ||
@@ -72,3 +72,4 @@ } | ||
*/ | ||
exports.OAuth2Error = require('./errors/oauth2error'); | ||
exports.AuthorizationError = require('./errors/authorizationerror'); | ||
exports.TokenError = require('./errors/tokenerror'); |
@@ -139,6 +139,6 @@ /** | ||
function immediated(err, allow, ares) { | ||
function immediated(err, allow, info, locals) { | ||
if (err) { return next(err); } | ||
if (allow) { | ||
req.oauth2.res = ares || {}; | ||
req.oauth2.res = info || {}; | ||
req.oauth2.res.allow = true; | ||
@@ -160,2 +160,18 @@ | ||
req.oauth2.transactionID = tid; | ||
// Add info and locals to `req.oauth2`, where they will be | ||
// available to the next middleware. Since this is a | ||
// non-immediate response, the next middleware's responsibility is | ||
// to prompt the user to allow or deny access. `info` and | ||
// `locals` are passed along as they may be of assistance when | ||
// rendering the prompt. | ||
// | ||
// Note that `info` is also serialized into the transaction, where | ||
// it can further be utilized in the `decision` middleware after | ||
// the user submits the prompt's form. As such, `info` should be | ||
// a normal JSON object, so that it can be correctly serialized | ||
// into the session. `locals` is only carried through to the | ||
// middleware chain for the current request, so it may contain | ||
// instantiated classes that don't serialize cleanly. | ||
req.oauth2.info = info; | ||
req.oauth2.locals = locals; | ||
@@ -167,2 +183,3 @@ var txn = {}; | ||
txn.req = areq; | ||
txn.info = info; | ||
// store transaction in session | ||
@@ -180,2 +197,6 @@ var txns = req.session[key] = req.session[key] || {}; | ||
immediate(req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, immediated); | ||
} else if (arity == 5) { | ||
immediate(req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, req.oauth2.req.type, immediated); | ||
} else if (arity == 6) { | ||
immediate(req.oauth2.client, req.oauth2.user, req.oauth2.req.scope, req.oauth2.req.type, req.oauth2.req, immediated); | ||
} else { // arity == 3 | ||
@@ -182,0 +203,0 @@ immediate(req.oauth2.client, req.oauth2.user, immediated); |
@@ -76,3 +76,3 @@ /** | ||
var enc = 'query'; | ||
if (req.oauth2 && req.oauth2.req) { | ||
if (req.oauth2.req) { | ||
var type = new UnorderedList(req.oauth2.req.type); | ||
@@ -79,0 +79,0 @@ // In accordance with [OAuth 2.0 Multiple Response Type Encoding |
@@ -30,3 +30,3 @@ /** | ||
* Some client deployments may be incapable of secure client authentication. | ||
* Applications are responsbile for determining what level of exposure is | ||
* Applications are responsible for determining what level of exposure is | ||
* acceptable, and handling such clients and displaying notices as appropriate. | ||
@@ -33,0 +33,0 @@ * |
@@ -62,2 +62,3 @@ /** | ||
req.oauth2.req = txn.req; | ||
req.oauth2.info = txn.info; | ||
next(); | ||
@@ -64,0 +65,0 @@ }); |
{ | ||
"name": "oauth2orize", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "OAuth 2.0 authorization server toolkit for Node.js.", | ||
@@ -16,2 +16,7 @@ "keywords": [ | ||
], | ||
"author": { | ||
"name": "Jared Hanson", | ||
"email": "jaredhanson@gmail.com", | ||
"url": "http://www.jaredhanson.net/" | ||
}, | ||
"repository": { | ||
@@ -24,7 +29,2 @@ "type": "git", | ||
}, | ||
"author": { | ||
"name": "Jared Hanson", | ||
"email": "jaredhanson@gmail.com", | ||
"url": "http://www.jaredhanson.net/" | ||
}, | ||
"licenses": [ | ||
@@ -40,6 +40,6 @@ { | ||
"utils-merge": "1.x.x", | ||
"debug": "0.7.x" | ||
"debug": "2.x.x" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.x.x", | ||
"mocha": "2.x.x", | ||
"chai": "1.x.x", | ||
@@ -46,0 +46,0 @@ "chai-connect-middleware": "0.3.x", |
# OAuth2orize | ||
[![Build](https://travis-ci.org/jaredhanson/oauth2orize.png)](http://travis-ci.org/jaredhanson/oauth2orize) | ||
[![Coverage](https://coveralls.io/repos/jaredhanson/oauth2orize/badge.png)](https://coveralls.io/r/jaredhanson/oauth2orize) | ||
[![Dependencies](https://david-dm.org/jaredhanson/oauth2orize.png)](http://david-dm.org/jaredhanson/oauth2orize) | ||
[![Build](https://travis-ci.org/jaredhanson/oauth2orize.svg?branch=master)](https://travis-ci.org/jaredhanson/oauth2orize) | ||
[![Coverage](https://coveralls.io/repos/jaredhanson/oauth2orize/badge.svg?branch=master)](https://coveralls.io/r/jaredhanson/oauth2orize) | ||
[![Quality](https://codeclimate.com/github/jaredhanson/oauth2orize/badges/gpa.svg)](https://codeclimate.com/github/jaredhanson/oauth2orize) | ||
[![Dependencies](https://david-dm.org/jaredhanson/oauth2orize.svg)](https://david-dm.org/jaredhanson/oauth2orize) | ||
[![Tips](https://img.shields.io/gratipay/jaredhanson.svg)](https://gratipay.com/jaredhanson/) | ||
@@ -177,2 +179,6 @@ | ||
## Debugging | ||
oauth2orize uses the [debug module](https://www.npmjs.org/package/debug). You can enable debugging messages on the console by doing ```export DEBUG=oauth2orize``` before running your application. | ||
## Credits | ||
@@ -186,2 +192,2 @@ | ||
Copyright (c) 2012-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)> | ||
Copyright (c) 2012-2015 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)> |
Sorry, the diff of this file is not supported yet
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
78860
1882
192
23
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)
- Removeddebug@0.7.4(transitive)
Updateddebug@2.x.x