# passport-cookie

> Cookie authentication strategy for Passport

Latest version **1.0.9** (published 2020-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install passport-cookie
pnpm add passport-cookie
yarn add passport-cookie
bun add passport-cookie
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2020-12-09 |
| First published | 2016-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 1 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | ROJO 2 |
| Maintainers | aitormm |
| Keywords | passport, auth, authn, authentication, token, cookie |

## Links

- npm: https://www.npmjs.com/package/passport-cookie
- Repository: https://github.com/rojo2/passport-cookie
- Homepage: https://github.com/rojo2/passport-cookie#readme
- Issues: http://github.com/rojo2.com/passport-cookie/issues
- npm.io page: https://npm.io/package/passport-cookie

## Dependencies (1)

- [passport-strategy](https://npm.io/package/passport-strategy.md) ^1.0.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2020-12-09
- 1.0.8 — 2020-06-13
- 1.0.7 — 2020-06-13
- 1.0.6 — 2018-03-05
- 1.0.5 — 2018-03-05
- 1.0.4 — 2016-10-24
- 1.0.2 — 2016-10-23
- 1.0.1 — 2016-10-23
- 1.0.0 — 2016-10-23

## README

# passport-cookie

[![Build Status](https://travis-ci.org/rojo2/passport-cookie.svg?branch=master)](https://travis-ci.org/rojo2/passport-cookie)
[![Coverage Status](https://coveralls.io/repos/github/rojo2/passport-cookie/badge.svg?branch=master)](https://coveralls.io/github/rojo2/passport-cookie?branch=master)

Cookie authentication strategy for [Passport](http://passportjs.org)

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](http://www.senchalabs.org/connect)-style
middleware, including [Express](http://expressjs.com/)..

## Install

```sh
$ 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.

```javascript
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`)

```javascript
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](http://expressjs.com/)
application:

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

## Tests

```sh
$ npm install
$ npm test
```

## Thanks

Thanks to [Jared Hanson](https://github.com/jaredhanson) for his great [Passport](http://passportjs.org)

## Contributors

- [AzazelN28](https://github.com/azazeln28)
- [Jershon](https://github.com/jylopez)
- [kai101](https://github.com/kai101)

## License

[The MIT License](http://opensource.org/licenses/MIT)

## Donate

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VL264WAE64MLQ&source=url)

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

---
_Source: https://npm.io/package/passport-cookie · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
