Neptunium, Promethium, Manganese

    koa-passport
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/koa-passport package

    4.1.4 • Public • Published

    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

    Install

    npm i koa-passport

    DownloadsWeekly Downloads

    93,070

    Version

    4.1.4

    License

    MIT

    Unpacked Size

    17 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar