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

1.0.1 • Public • Published

passport-anonymous

Build Coverage Dependencies

Passport strategy for anonymous authentication.

This module lets you provide anonymous authentication in your Node.js applications. By plugging into Passport, anonymous authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-anonymous

Usage

Configure Strategy

The anonymous authentication strategy passes authentication for a request, with req.user remaining undefined.

passport.use(new AnonymousStrategy());

Authenticate Requests

Use passport.authenticate(), specifying the 'anonymous' strategy, to pass authentication of a request. This is typically used alongside a strategy that verifies credentials, as a fallback for routes that prefer authentication but can also respond to unauthenticated requests.

For example, as route middleware in an Express application:

app.post('/hello', 
  passport.authenticate(['basic', 'anonymous'], { session: false }),
  function(req, res) {
    if (req.user) {
      res.json({ name: req.user.username });
    } else {
      res.json({ name: 'anonymous' });
    }
  });

Examples

For a complete, working example, refer to the login example.

Tests

$ npm install
$ npm test

Credits

License

The MIT License

Copyright (c) 2012-2013 Jared Hanson <http://jaredhanson.net/>

Readme

Keywords

none

Package Sidebar

Install

npm i passport-anonymous

Weekly Downloads

65,237

Version

1.0.1

License

none

Last publish

Collaborators

  • jaredhanson