项目作者: nash403

项目描述 :
Anonymous authentication strategy for Passport that supply an uuid.
高级语言: JavaScript
项目地址: git://github.com/nash403/passport-anonym-uuid.git
创建时间: 2017-02-23T12:26:30Z
项目社区:https://github.com/nash403/passport-anonym-uuid

开源协议:MIT License

下载


passport-anonym-uuid

Passport strategy for anonymous authentication with a unique uuid for the anonymous user.

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

  1. $ npm install passport-anonym-uuid

Usage

Configure Strategy

The anonymous authentication strategy passes authentication for a request,
with req.user supplied with {uuid: "anonymous_<uuid>"}.

  1. passport.use(new AnonymIdStrategy());

If you pass a done verify function to the strategy it will be supplied with req and the generated uuid.
With such verify callback, you can use this strategy the same way as passport-req. The strategy will not touch the user object returned by the callback.

Authenticate Requests

Use passport.authenticate(), specifying the 'anonymId' 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:

  1. app.post('/hello',
  2. passport.authenticate(['basic', 'anonymId'], { session: false }),
  3. function(req, res) {
  4. if (!req.user.uuid) {
  5. res.json({ name: req.user.username });
  6. } else {
  7. res.json({ name: req.user.uuid });
  8. }
  9. });

Examples

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

Tests

  1. $ npm install
  2. $ npm test

Credits

This package is almost a copy of passport-anonymous made by Jared Hanson.

License

The MIT License

Copyright (c) 2017 Honoré Nintunze