Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-cookie

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-cookie

Cookie authentication strategy for Passport

  • 1.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-0.65%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status

Cookie authentication strategy for Passport

This module lets you authenticate HTTP requests using cookies, it only allows you to recover the content of a cookie.

By plugging into Passport, bearer token support can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express..

Install

$ npm install passport-cookie

Usage

Configure Strategy

The cookie authentication strategy authenticates users using a cookie. The strategy requires a verify callback, which accepts that credential and calls done providing a user.

passport.use(new CookieStrategy(
  function(token, done) {
    User.findByToken({ token: token }, function(err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      return done(null, user);
    });
  }
));

You can pass the following options to the CookieStrategy:

- `cookieName`: Cookie name (defaults to "token")
- `signed`: Are the cookie signed? (defaults to false)
- `passReqToCallback`: when `true`, `req` is the first argument to the verify callback (default: `false`)
passport.use(new CookieStrategy({
  cookieName: 'auth',
  signed: true,
  passReqToCallback: true
}, function(req, token, done) {
  User.findByToken({ token: token }, function(err, user) {
    if (err) { return done(err); }
    if (!user) { return done(null, false); }
    return done(null, user);
  });
})
Authenticate Requests

Use passport.authenticate(), specifying the 'cookie' strategy, to authenticate requests. Requests containing cookies do not require session support, so the session option can be set to false.

For example, as route middleware in an Express application:

app.get("/profile",
  passport.authenticate("cookie", { session: false }),
  function(req, res) {
    res.json(req.user);
  });

Tests

$ npm install
$ npm test

Thanks

Thanks to Jared Hanson for his great Passport

Contributors

License

The MIT License

Donate

Donate

Made with ❤ by ROJO 2 (http://rojo2.com)

Keywords

FAQs

Package last updated on 09 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc