# passport-access-token

> Local access token authentication strategy for Passport.

Latest version **1.0.3** (published 2017-01-19) · 0 weekly downloads

## Install

```sh
npm install passport-access-token
pnpm add passport-access-token
yarn add passport-access-token
bun add passport-access-token
```

## 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.3 |
| Published | 2017-01-19 |
| First published | 2015-03-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.4.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Christian Vaas |
| Maintainers | auspex |
| Keywords | passport, local, token, auth, authn, authentication |

## Links

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

## Dependencies (1)

- [passport-strategy](https://npm.io/package/passport-strategy.md) 1.x.x

## Alternatives

- [@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
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2017-01-19
- 1.0.2 — 2015-03-18
- 1.0.1 — 2015-03-17
- 1.0.0 — 2015-03-17

## README

# passport-access-token [![Version npm](https://img.shields.io/npm/v/passport-access-token.svg?style=flat-square)](https://www.npmjs.com/package/passport-access-token)[![Dependencies](https://img.shields.io/david/auspexeu/passport-access-token.svg?style=flat-square)](https://david-dm.org/auspexeu/passport-access-token)

[![NPM](https://nodei.co/npm/passport-access-token.png?downloads=true&stars=true)](https://nodei.co/npm/passport-access-token/)

[Passport](http://passportjs.org/) strategy for authenticating with an access token.

This module lets you authenticate using an access token in your Node.js applications. By plugging into Passport, token based authentication 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/).

This can easily be used to create a password reset mechanism by providing the user with a link containing an access token that is then instantaneously revoked as soon as she sets a new password.

## Install

    $ npm install passport-access-token --save

## Usage

#### Configure Strategy

The local authentication strategy authenticates users using an access token. The strategy requires a `verify` callback, which accepts these
credentials and calls `done` providing a user.

    const AccessTokenStrategy = require('passport-access-token').Strategy
    passport.use(new AccessTokenStrategy({
        tokenParam: 'token'
      }, (token, done) => {
        User.findOne({ onetimePassword: token }, (err, user) => {
          if (err) { return done(err); }
          if (!user) { return done(null, false); }
          // delete the onetimePassword after the user has set the new password
          return done(null, user);
        });
      }
    ));

##### Options

The access token can be stored in three different locations which are configured as follows:

* Inside the url the HTTP GET parameter is specified using the `tokenParam` option (default: 'token')
* As a HTTP HEADER field which is specified using the `tokenHeader` option (default: 'accessToken')
* In the payload of a HTTP POST request where the field name is specified using the `tokenField` option (default: 'Authorization')
* If none of the above methods suits your purposes there is also the `extractor` option that can be supplied with a function of the signature 
function (req) {...} which returns the access token retrieved by some custom code from the HTTP request (default: *undefined*)

#### Authenticate Requests

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

For example, as route middleware in an [Express](http://expressjs.com/)
application:

    app.get('/login/:token', 
      passport.authenticate('token', { failureRedirect: '/login' }),
      (req, res) => {
        res.redirect('/');
      });

## Credits

  - [Jared Hanson](http://github.com/jaredhanson)

## License

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

Copyright (c) 2015 Christian Vaas

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