Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rkusa/koa-passport
Passport middleware for Koa
https://github.com/rkusa/koa-passport
authentication javascript koa koa2 passport
Last synced: 3 days ago
JSON representation
Passport middleware for Koa
- Host: GitHub
- URL: https://github.com/rkusa/koa-passport
- Owner: rkusa
- License: mit
- Created: 2014-01-15T01:33:36.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2023-04-13T04:58:16.000Z (almost 2 years ago)
- Last Synced: 2025-01-02T18:09:59.683Z (10 days ago)
- Topics: authentication, javascript, koa, koa2, passport
- Language: JavaScript
- Homepage:
- Size: 268 KB
- Stars: 773
- Watchers: 13
- Forks: 54
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-humanscape - koa-passport - 사용자 authenticate를 위한 middleware (Node.js, koa / Utilites)
- awesome-koa - koa-passport - 基于Passport的鉴权中间件。 ![](https://img.shields.io/github/stars/rkusa/koa-passport.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-passport.svg?style=flat-square) (仓库 / 中间件)
README
# koa-passport
[Passport](https://github.com/jaredhanson/passport) middleware for Koa
[![NPM][npm]](https://npmjs.org/package/koa-passport)
koa-passport version | passport version | koa version | branch
--------------------- | ---------------- | ------------| ------
6.x, 5.x | 6.x, 5.x | 2.x | main
4.x | 4.x | 2.x | v3.x
3.x, 2.x | 2.x | 2.x | v2.x
1.x | 1.x | 1.x | v1.x## Usage
```js
// body parser
const bodyParser = require('koa-bodyparser')
app.use(bodyParser())// Sessions
const session = require('koa-session')
app.keys = ['secret']
app.use(session({}, app))const passport = require('koa-passport')
app.use(passport.initialize())
app.use(passport.session())
```[Example Application](https://github.com/rkusa/koa-passport-example)
Passport's values and methods are exposed as follows:
```js
app.use(async ctx => {
ctx.isAuthenticated()
ctx.isUnauthenticated()
await ctx.login()
ctx.logout()
ctx.state.user
})
```## License
[MIT](LICENSE)
[npm]: http://img.shields.io/npm/v/koa-passport.svg
[dependencies]: http://img.shields.io/david/rkusa/koa-passport.svg
[travis]: https://travis-ci.org/rkusa/koa-passport.svg?branch=master