passport-automatic
Automatic.com authentication strategy for Passport
Last updated 5 years ago by brendannee .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install passport-automatic 
SYNC missed versions from official npm registry.

Passport-Automatic

Passport strategy for authenticating with Automatic using the OAuth 2.0 API.

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

Install

$ npm install passport-automatic

Usage

Configure Strategy

The Automatic authentication strategy authenticates users using a GitHub account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a client ID, client secret, and callback URL.

passport.use(new AutomaticStrategy({
    clientID: AUTOMATIC_CLIENT_ID,
    clientSecret: AUTOMATIC_CLIENT_SECRET,
    scope: ['scope:user:profile', 'scope:trip', 'scope:location', 'scope:vehicle:profile', 'scope:vehicle:events', 'scope:behavior']
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ automaticId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/automatic',
  passport.authenticate('automatic'));

app.get('/auth/automatic/callback',
  passport.authenticate('automatic', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Get Access Token

Passport adds a user attribute to req, so you can get the access token with req.user.accessToken.

Example:

//fetches most recent 25 trips
request.get({
  uri: 'https://api.automatic.com/trip/',
  headers: {Authorization: 'bearer ' + req.user.accessToken},
  json: true
}, function(e, r, body) {
  //body contains api response
});

Credits

License

This project is licensed under the terms of the Apache 2.0 license.

Current Tags

  • 1.2.1                                ...           latest (5 years ago)

4 Versions

  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |