Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-automatic

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-automatic

Automatic.com authentication strategy for Passport

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

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.

Keywords

FAQs

Package last updated on 23 Apr 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