Code Monkey home page Code Monkey logo

passport's Introduction

Passport

http://passportjs.org

Passport is an authentication framework for Connect and Express, which is extensible through "plugins" known as strategies.

Passport is designed to be a general-purpose, yet simple, modular, and unobtrusive, authentication framework. Passport's sole purpose is to authenticate requests. In being modular, it doesn't force any particular authentication strategy on your application. In being unobtrusive, it doesn't mount routes in your application. The API is simple: you give Passport a request to authenticate, and Passport provides hooks for controlling what occurs when authentication succeeds or fails.

Installation

$ npm install passport

Usage

Strategies

Passport uses the concept of strategies to authenticate requests. Strategies can range from verifying username and password credentials, delegated authentication using OAuth (for example, via Facebook or Twitter), or federated authentication using OpenID.

Before asking passport to authenticate a request, the strategy (or strategies) used by an application must be configured.

passport.use(new LocalStrategy(
  function(username, password, done) {
    User.findOne({ username: username, password: password }, function (err, user) {
      done(err, user);
    });
  }
));

Sessions

Passport will maintain persistent login sessions. In order for persistent sessions to work, the authenticated user must be serialized to the session, and deserialized when subsequent requests are made.

Passport does not impose any restrictions on how your user records are stored. Instead, you provide a function to Passport which implements the necessary serialization and deserialization logic. In typical applications, this will be as simple as serializing the user ID, and finding the user by ID when deserializing.

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, function (err, user) {
    done(err, user);
  });
});

Connect/Express Middleware

To use Passport in a Connect or Express-based application, configure it with the required passport.initialize() middleware. If your applications uses persistent login sessions (recommended, but not required), passport.session() middleware must also be used.

app.configure(function() {
  app.use(express.cookieParser());
  app.use(express.bodyParser());
  app.use(express.session({ secret: 'keyboard cat' }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(app.router);
  app.use(express.static(__dirname + '/../../public'));
});

Authenticate Requests

Passport provides an authenticate() function (which is standard Connect/Express middleware), which is utilized to authenticate requests.

For example, it can be used as route middleware in an Express application:

app.post('/login', 
  passport.authenticate('local', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
  });

Examples

For a complete, working example, refer to the login example included in Passport-Local.

Strategies

StrategyDescriptionDeveloper
LocalLocal username and password authentication strategy.
OpenIDOpenID authentication strategy.
OAuthOAuth 1.0 and 2.0 authentication strategies.
BrowserIDBrowserID authentication strategy.
WebIDWebID authentication strategy.Baptiste Lafontaine
37signals37signals authentication strategy.
AngelListAngelList authentication strategy.
BitbucketBitbucket authentication strategy.
DiggDigg authentication strategy.
DropboxDropbox authentication strategy.
DwollaDwolla authentication strategy.
EvernoteEvernote authentication strategy.
FacebookFacebook authentication strategy.
FitbitFitbit authentication strategy.
FlattrFlattr authentication strategy.Johan Uhle
FlickrFlickr authentication strategy.Johnny Halife
Force.comForce.com (Salesforce, Database.com) authentication strategy.Joshua Birk
FoursquareFoursquare authentication strategy.
GeoloqiGeoloqi authentication strategy.
GitHubGitHub authentication strategy.
GoodreadsGoodreads authentication strategy.
GoogleGoogle authentication strategy.
Google (OAuth)Google (OAuth 1.0 and OAuth 2.0) authentication strategies.
GowallaGowalla authentication strategy.
InstagramInstagram authentication strategy.
Justin.tvJustin.tv authentication strategy.
LinkedInLinkedIn authentication strategy.
MeetupMeetup authentication strategy.
NetflixNetflix authentication strategy.
OhlohOhloh authentication strategy.
OpenStreetMapOpenStreetMap authentication strategy.
picplzpicplz authentication strategy.
RdioRdio authentication strategy.
ReadabilityReadability authentication strategy.
RunKeeperRunKeeper authentication strategy.
SmugMugSmugMug authentication strategy.
SoundCloudSoundCloud authentication strategy.
StatusNetStatusNet authentication strategy.ZooWar
SteamSteam authentication strategy.Liam Curry
TripItTripIt authentication strategy.
TumblrTumblr authentication strategy.
TwitterTwitter authentication strategy.
VimeoVimeo authentication strategy.
Windows LiveWindows Live authentication strategy.
Yahoo!Yahoo! authentication strategy.
Yahoo! (OAuth)Yahoo! (OAuth 1.0) authentication strategy.
YammerYammer authentication strategy.
HTTPHTTP Basic and Digest authentication strategies.
HTTP-BearerHTTP Bearer authentication strategy.
DummyDummy authentication strategy.Development Seed

Tests

$ npm install --dev
$ make test

Build Status

Credits

License

(The MIT License)

Copyright (c) 2011 Jared Hanson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

passport's People

Contributors

jaredhanson avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.