npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sails-hook-passport

v0.3.3

Published

Implement basic Passport.js authentification strategies

Downloads

77

Readme

sails-hook-passport

Implement passport.js strategies to log your users with twitter, facebook, google and more...

##INSTALL Install it with npm :

npm install --save sails-hook-passport

You need to install all strategies you want to use :

npm install --save passport-local passport-twitter passport-facebook

##CONFIGURE Basic embedded user models is (you don't need to create it) :

var User = 
{
  schema : true,
  attributes : {
      username  : {
          type   : 'string',
          unique : true
      },
      email     : {
          type   : 'email',
          unique : true
      },
      passports : {
          collection : 'Passport',
          via        : 'user'
      }
  }
};

You can override this model by creating a User.js under your api/models folder and add more attributes and callbacks.

By default password have to be >= 8 characters, you can also override it by creating a Passport.js under api/models like this :

module.exports = {

  attributes : {
    password : {
      type      : 'string',
      minLength : 6
    }
  }
};

Add translation on your config/locales/...

{
    "Error.Passport.Password.Invalid": "The provided password is invalid!",
    "Error.Passport.Password.Wrong": "Whoa, that password wasn't quite right!",
    "Error.Passport.Password.NotSet": "Oh no, you haven't set a password yet!",
    "Error.Passport.Username.NotFound": "Uhm, what's your name again?",
    "Error.Passport.User.Exists": "This username is already taken.",
    "Error.Passport.Email.NotFound": "That email doesn't seem right",
    "Error.Passport.Email.Missing": "You need to supply an email-address for verification",
    "Error.Passport.Email.Exists": "This email already exists. So try logging in.",
    "Error.Passport.Username.Missing": "You need to supply a username",
    "Error.Passport.Password.Missing": "Oh no, you haven't set a password yet!",
    "Error.Passport.Generic": "Snap. Something went wrong with authorization.",
    "Error.ResetPassword" : "An error as occurred, please restart the procedure",
    "Error.ResetPassword.Token" : "This link is no more valid, please restart the procedure",
    "Success.ResetPassword" : "Your password is changed successfully",
    "Email.Sent" : "An email was sent to change your password"
}

Enable passport strategies on config/passport.js file :

module.exports.passport = {
    redirect : 
    {
  		login 		: "/",//Login successful
  		logout		: "/"//Logout successful
  	},
  	layout : "layout", //Specify the layout file for auth views
  	passwordResetTokenValidity : 86400000, //Link to reset password is good the next 24h after asking
    onUserCreated : function (user, providerInfos)//providerInfos is infos from twitter/facebook... 
  	{
  		//Send email for example
  	},
  	onUserLogged  : function (session, user)
    {
        //Set user infos in session for example
    },
    onUserAskNewPassword : function (req, userData, callback)
    {
        //You can here send an email, an example of email template is available under /views/auth/emails
        //var protocol  = req.connection.encrypted ? 'https' : 'http';
        //var baseUrl   = protocol + '://' + req.headers.host + '/';
        //Use your favorite email sender :)
        //don't forget to call the callback with optional error parameter
        //URL to call : resetPassword?email=<%=user.email%>&token=user.mdpToken
 		callback();
    },
  	strategies : {
  		local : {
  			strategy : require('passport-local').Strategy
  		},
  
  		twitter : {
  			name     : 'Twitter',
  			protocol : 'oauth',
  			strategy : require('passport-twitter').Strategy,
  			options  : {
  				consumerKey    : 'your-consumer-key',
  				consumerSecret : 'your-consumer-secret'
  			}
  		},
  
  		facebook : {
  			name     : 'Facebook',
  			protocol : 'oauth2',
  			strategy : require('passport-facebook').Strategy,
  			options  : {
  				clientID     : 'your-client-id',
  				clientSecret : 'your-client-secret',
  				scope        : ['email'] /* email is necessary for login behavior */
  			}
  		},
  
  		google : {
  			name     : 'Google',
  			protocol : 'oauth2',
  			strategy : require('passport-google-oauth').OAuth2Strategy,
  			options  : {
  				clientID     : 'your-client-id',
  				clientSecret : 'your-client-secret'
  			}
  		}
  	}
};

You can log and register on /login and /register routes.

###WARNING Don't install passport on your sails projet or hook will not working anymore. If you really need passport on your sails project remove passport from sails-hook-passport module