koa-passport
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -22,19 +22,16 @@ /** | ||
return function* passportInitialize(next) { | ||
// koa <-> connect compatibility | ||
this.req.session = this.session | ||
this.req.query = this.request.query | ||
this.req.body = this.request.body | ||
// koa <-> connect compatibility: | ||
this.passport = {} | ||
var req = createReqMock(this) | ||
// add aliases for passport's request extensions to `ctx` | ||
var ctx = this | ||
ctx.login = ctx.logIn = function(user, options) { | ||
return function(done) { | ||
ctx.req.login(user, options, done) | ||
} | ||
var ctx = this, login = ctx.req.login | ||
ctx.login = ctx.logIn = ctx.req.login = function(user, options) { | ||
return login.bind(req, user, options) | ||
} | ||
ctx.logout = ctx.logOut = ctx.req.logout.bind(ctx.req) | ||
ctx.isAuthenticated = ctx.req.isAuthenticated.bind(ctx.req) | ||
ctx.isUnauthenticated = ctx.req.isUnauthenticated.bind(ctx.req) | ||
ctx.logout = ctx.logOut = ctx.req.logout = ctx.req.logout.bind(req) | ||
ctx.isAuthenticated = ctx.req.isAuthenticated = ctx.req.isAuthenticated.bind(req) | ||
ctx.isUnauthenticated = ctx.req.isUnauthenticated = ctx.req.isUnauthenticated.bind(req) | ||
yield middleware.bind(middleware, this.req, this) | ||
yield middleware.bind(middleware, req, this) | ||
yield next | ||
@@ -88,2 +85,5 @@ } | ||
var cont = yield function(done) { | ||
// mock the `req` object | ||
var req = createReqMock(ctx) | ||
// mock the `res` object | ||
@@ -113,3 +113,3 @@ var res = { | ||
// call the connect middleware | ||
middleware(ctx.req, res, done) | ||
middleware(req, res, done) | ||
} | ||
@@ -142,1 +142,14 @@ | ||
} | ||
// create | ||
var handler = require('node-proxy-defaults') | ||
function createReqMock(ctx) { | ||
// Use a proxy that forwards `req` reads to either `ctx.passport`, | ||
// Node's request, Koa's request or Koa's context. Writes are persistet | ||
// into `ctx.passport`. | ||
return Proxy.create(handler(ctx.passport, { | ||
get: function(receiver, key) { | ||
return ctx.passport[key] || ctx.req[key] || ctx.request[key] || ctx[key] | ||
} | ||
})) | ||
} |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Passport middleware for Koa", | ||
@@ -20,2 +20,3 @@ "keywords": [ | ||
"co": "^3.0.6", | ||
"node-proxy-defaults": "^1.0.0", | ||
"passport": ">=0.2.x" | ||
@@ -22,0 +23,0 @@ }, |
# koa-passport | ||
[![NPM](https://badge.fury.io/js/koa-passport.svg)](https://npmjs.org/package/koa-passport) | ||
[![Dependency Status](https://david-dm.org/rkusa/koa-passport.svg?theme=shields.io)](https://david-dm.org/rkusa/koa-passport) | ||
[Passport](https://github.com/jaredhanson/passport) middleware for Koa | ||
## Example | ||
[![NPM][npm]](https://npmjs.org/package/koa-passport) | ||
[![Dependency Status][dependencies]](https://david-dm.org/rkusa/koa-passport) | ||
## Usage | ||
```js | ||
@@ -26,2 +27,4 @@ // body parser | ||
Note: You have to start your Koa application with `node --harmony app.js` or `node --harmony-generators --harmony-proxies app.js` (enable both `generators` and `proxies`). | ||
## MIT License | ||
@@ -46,2 +49,5 @@ | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[npm]: http://img.shields.io/npm/v/koa-passport.svg?style=flat | ||
[dependencies]: http://img.shields.io/gemnasium/rkusa/koa-passport.svg?style=flat |
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
9050
7
136
51
3
+ Addednode-proxy-defaults@^1.0.0
+ Addednode-proxy-defaults@1.0.0(transitive)