trailsjs / sails-auth

Passport-based User Authentication system for sails.js applications. Designed to work well with the sails-permissions module.
https://www.npmjs.org/package/sails-auth
MIT License
266 stars 141 forks source link

Is there any documentation as to how to use this package? #131

Closed thescopan closed 8 years ago

thescopan commented 8 years ago

I am new to sails and the first thing I wanted to implement was auth. But the readme does not explain anything about the usage.

subwaymatch commented 8 years ago

+1. Wishing for a documentation or some kind of example.

alexanderzone commented 8 years ago

+1

CovertIII commented 8 years ago

I had a difficult time learning this too. I had to read through the source code to get an idea of what was going on and how to use it. The local strategy is enabled by default, so take a look at the wiki pages to get an idea of how to use it. For third party provider, here's a brief explanation: Basically in your sails project you have to edit config/passport.js to use the strategies you want in your app, then hit the correct endpoint to authenticate them. You also have to configure whatever service your using with the correct callback urls.

This project has a few examples of strategies commented out in config/passport.js. You put the ones you want in your config/passport.js and make sure you install the correct npm package associated with the strategy.

Then set up your app in Google/Facebook/Twitter, etc and input the correct clientID and clientSecret in config/passport.js for whatever service your using.

To authenticate, you go to /auth/google or /auth/facebook or whatever provider your using. The provider will ask you if it's okay for your app to hook up, you say yes, then the provider will redirect to the callback url, which will be /auth/provider/callback (ex. /auth/google/callback or /auth/facebook/callback). Make sure you've configured your app in the provider your using with the correct callback urls or in some cases you'll get an error. You can also specify a callback url per provider, by editing it in config/passport.js. For example:

google: {
    name: 'Google',
    protocol: 'oauth2',
    strategy: require('passport-google-oauth').OAuth2Strategy,
    options: {
      clientID: 'CLIENT_ID',
      clientSecret: 'CLIENT_SECRET',
      scope: ['profile', 'email'],
      callbackURL: 'https://www.example.com/auth/google/callback?next=/user/afterAuth'
    }
}

See the comments in this file https://github.com/tjwebb/sails-auth/blob/master/api/services/passport.js to see how sails-auth connects users with passports.

subwaymatch commented 8 years ago

Even for local strategy, it would be nice if there were basic examples for:

tjwebb commented 8 years ago

There is documentation here: https://github.com/tjwebb/sails-auth/wiki

Contributions are welcome and encouraged. Believe it or not, there's an actual limit to how much work I can do for free.