Socket
Socket
Sign inDemoInstall

passport-auth-token

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-auth-token

Authentication token strategy for Passport.


Version published
Weekly downloads
6.9K
increased by4.41%
Maintainers
1
Weekly downloads
 
Created
Source

passport-auth-token

Build Coverage Status Quality Dependencies

Passport strategy for authenticating with an authentication token.

This module lets you authenticate using a token in your Node.js applications. It is based on passport-local module by Jared Hanson. By plugging into Passport, token authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-auth-token

Usage

Configure Strategy

The token authentication strategy authenticates users using a token. The strategy requires a verify callback, which accepts these credentials and calls done providing a user. Here is the pseudo code.

passport.use('authtoken', new AuthTokenStrategy(
  function(token, done) {
    AccessToken.findOne({
      id: token
    }, function(error, accessToken) {
      if (error) {
        return done(error);
      }

      if (accessToken) {
        if (!token.isValid(accessToken)) {
          return done(null, false);
        }

        User.findOne({
          id: accessToken.userId
        }, function(error, user) {
          if (error) {
            return done(error);
          }

          if (!user) {
            return done(null, false);
          }

          return done(null, user);
        });
      } else {
        return done(null);
      }
    });
  }
));
Authenticate Requests

Use passport.authenticate(), specifying the 'authtoken' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.post('/login',
  passport.authenticate(
    'authtoken',
    {
      session: false,
      optional: false
    }
  ),
  function(req, res) {
    res.redirect('/');
  }
);

You can also set the parameter optional to true, so the same call can be both authenticated and not authenticated.

Examples

For complete, working examples, refer to the multiple examples included. (NOT UPDATED)

Tests

$ npm install
$ npm test

Credits

  • Mike Bell

License

The MIT License

Copyright (c) 2014 Mike Bell

Keywords

FAQs

Package last updated on 24 Feb 2015

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