How to authenticate a Sails JS application using a passport?

I am using Sails v0.10.5. I want to integrate the authentication system with username and password using Passport. To do this, I looked at the following documents:

But, I saw in the comments that they are outdated and no longer work with sails v0.10.5. I tried this, this is not authentication, and I was able to access all the actions of the controller without any authentication.

Is there an updated version or any other useful documentation for integration?

+4
source share
3 answers

I highly recommend you try the sails-generate-auth generator. It is passport-based and creates the entire authentication level for your sails.js application, including local policy (user / password), OAuth2.0, and OpenID.

Sails-generate-auth will create two new models for you (User, Passport), an authentication controller, a service, and route and policy settings. Therefore, if you want to apply authentication to an existing application, it would be safer to create a new sailing application, generate an authentication level using sails-generate-auth, test it a little and then copy the necessary files to the original application.

Hope this helps.

Edit

sails-auth . sails-generate-auth, , .

+6

sails.js passport.js, , Twitter, Facebook: https://github.com/bmustata/sails-auth-super-template

+1

sails-generate-auth, sails-auth waterlock , , . , . - .

1 (Globals): $npm install -g

2 (): $sails new myApp

3 (): https://github.com/carlospliego/sails-token-auth-setup

4 (): /policy.js

 '*': "hasToken",
 UserController: {
    "create": true
 },
 AuthController: {
    '*': true
 }

5: config/tokenSecret.js

6: ()

  • npm install --save
  • npm install --save -
  • npm install --save bcrypt-nodejs
  • npm install --save jsonwebtoken
  • npm install --save express-jwt

:

  • POST/GET/PUT/DELETE /
  • POST auth/login
  • DELETE auth/logout

: https://github.com/carlospliego/sails-token-auth-setup

0

All Articles