https://github.com/dowjones/passport-http-encrypted-token
HTTP Encrypted Token authentication strategy for Passport and Node.js
https://github.com/dowjones/passport-http-encrypted-token
authentication-strategy encrypted-tokens passport passport-bearer strategy
Last synced: about 2 months ago
JSON representation
HTTP Encrypted Token authentication strategy for Passport and Node.js
- Host: GitHub
- URL: https://github.com/dowjones/passport-http-encrypted-token
- Owner: dowjones
- License: isc
- Created: 2016-10-17T15:18:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-04T20:20:35.000Z (about 3 years ago)
- Last Synced: 2025-03-15T07:48:09.871Z (2 months ago)
- Topics: authentication-strategy, encrypted-tokens, passport, passport-bearer, strategy
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# passport-http-encrypted-token
[](https://www.npmjs.com/package/passport-http-encrypted-token) [](https://travis-ci.org/dowjones/passport-http-encrypted-token) [](https://codeclimate.com/github/dowjones/passport-http-encrypted-token) [](https://coveralls.io/github/dowjones/passport-http-encrypted-token?branch=master)
HTTP Encrypted Token authentication strategy for [Passport](http://passportjs.org/).
This module lets you authenticate HTTP requests using encrypted tokens
in your Node.js applications. **Encrypted_token** is a custom authentication
scheme used by Professional Information Business (PIB) group in Dow Jones.
Encrypted tokens are typically used protect API endpoints, and are
issued using Dow Jones Session server.By plugging into Passport, encrypted 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/) and [Koa](https://github.com/rkusa/koa-passport).This work is based on [passport-http-bearer](https://github.com/jaredhanson/passport-http-bearer).
## Install
```console
$ npm install passport-http-encrypted-token
```## Usage
#### Configure Strategy
The HTTP Encrypted token authentication strategy authenticates users using a encrypted_token.
The strategy requires a `verify` callback, which accepts that
credential and calls `done` providing a user.```js
const EncryptedTokenStrategy = require('passport-http-encrypted-token').Strategypassport.use(new EncryptedTokenStrategy(
function(token, done) {
User.findOne({ 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 `'Encrypted_token'` strategy, to
authenticate requests. Requests containing encrypted tokens 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:```js
app.get('/profile',
passport.authenticate('Encrypted_token', { session: false }),
function(req, res) {
res.json(req.user)
}
)
````## Tests
```console
$ npm install
$ npm test
```## Example
Use `curl` to send an authenticated request.
```bash
$ curl -H "Authorization: Encrypted_token 123456789" http://127.0.0.1:3000/
```## Credits
- [Jared Hanson](http://github.com/jaredhanson) (passport bearer auth implementation)
## License
[ISC](/LICENSE)
Released 2016 by [Hrusikesh Panda](https://github.com/mrchief) @ [Dow Jones](https://github.com/dowjones)