Giter VIP home page Giter VIP logo

koa-passport's Introduction

koa-passport

Passport middleware for Koa

NPM Dependency Status Build Status

koa-passport version koa version branch
1.x 1.x v1.x
2.x 2.x v2.x
4.x 2.x master

Migration to v3

  • change ctx.passport.* to ctx.state.* (e.g. ctx.passport.user to ctx.state.user)
  • don't call passport methods on ctx.req (e.g. use ctx.login instead of ctx.req.login)
  • update custom authentication callback arguments to err, user, info, status (e.g. passport.authenticate('local', function(err, user, info, status) { ... })(ctx, next))

Usage

// 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

Passport's values and methods are exposed as follows:

app.use(async ctx => {
  ctx.isAuthenticated()
  ctx.isUnauthenticated()
  await ctx.login()
  ctx.logout()
  ctx.state.user
})

License

MIT

koa-passport's People

Contributors

aghost-7 avatar cayasso avatar chentsulin avatar cr1s avatar dizlexik avatar fundon avatar gingerich avatar greenkeeperio-bot avatar iliakan avatar jiangjie avatar jpetitcolas avatar kherock avatar kudos avatar pesho avatar rkusa avatar roymiloh avatar tigerc10 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.