Comments (7)
I'm having an issue trying to use login.
Can you describe in more detail what you tried to do, and what didn't seem to work?
from sails-auth.
Thanks @tjwebb for the quick reply. When I use the route 'auth/local/:callback' by calling 'auth/local/login' it should hit the service/protocols/local.js login export, however when the request get's routed through services/passport.js the login action is missing, causing it to return "Invalid Action." I could be wrong, but in the current code base, there is no way to preform a passport local login which should look like this:
else if (action === 'login' && !req.user) {
this.protocols.local.login(req, res, next);
}
from sails-auth.
I can verify that this works:
// api/services/passport.js
var _ = require('lodash');
var _super = require('sails-permissions/api/services/passport');
function passport () { }
passport.prototype = Object.create(_super);
_.extend(passport.prototype, {
// Extend with custom logic here by adding additional fields and methods,
// and/or overriding methods in the superclass.
/**
* For example:
*
* foo: function (bar) {
* bar.x = 1;
* bar.y = 2;
* return _super.foo.call(this, bar);
* }
*/
callback: function (req, res, next) {
var provider = req.param('provider', 'local');
var action = req.param('action');
// Passport.js wasn't really built for local user registration, but it's nice
// having it tied into everything else.
if (provider === 'local' && action !== undefined) {
if (action === 'register' && !req.user) {
this.protocols.local.register(req, res, next);
}
else if (action === 'login' && !req.user) {
this.protocols.local.login(req, res, next);
}
else if (action === 'connect' && req.user) {
this.protocols.local.connect(req, res, next);
}
else if (action === 'disconnect' && req.user) {
this.protocols.local.disconnect(req, res, next);
}
else {
next(new Error('Invalid action'));
}
} else {
if (action === 'disconnect' && req.user) {
this.disconnect(req, res, next) ;
} else {
// The provider will redirect the user to this URL after approval. Finish
// the authentication process by attempting to obtain an access token. If
// access was granted, the user will be logged in. Otherwise, authentication
// has failed.
this.authenticate(provider, next)(req, res, req.next);
}
}
}
});
module.exports = new passport();
It just overrides the default callback method when sails-auth is used with sails-permissions. I hope that helps in your investigation.
from sails-auth.
Hey Scott...The unit tests in this file show you how to authenticate: https://github.com/tjwebb/sails-auth/blob/master/test/unit/controllers/AuthController.test.js
from sails-auth.
Oh snap @bgulotta thanks man, I'll give it a go.
from sails-auth.
@bgulotta is correct, you can just point a login form to /auth/local and login works. My initial assumption was wrong about the missing login function.
from sails-auth.
Hi guys !
I wonder when action becomes "login" as it sends me undefined all the time ?
var action = req.param('action');
if (action === 'register') {
res.redirect('/register');
}
else if (action === 'login') {
res.redirect('/login');
}
else if (action === 'disconnect') {
res.redirect('back');
}
else {
// make sure the server always returns a response to the client
// i.e passport-local bad username/email or password
res.forbidden();
}
And this logic works in sails-generate-auth and it's a bit different:
switch (action) {
case 'register':
res.redirect('/register');
break;
case 'disconnect':
res.redirect('back');
break;
default:
res.redirect('/login');
}
from sails-auth.
Related Issues (20)
- Is the project still active? HOT 1
- sails.getBaseURL() is deprecated. HOT 14
- Deprecated project? HOT 1
- Broken with sails 0.12.3 HOT 2
- unique: true works bad with sails-mongo. HOT 1
- LDAP auth HOT 2
- req.user always empty when calling /user/me HOT 4
- action=login error HOT 2
- login sample HOT 1
- NPM HOT 8
- LinkedIn Passport provider saved as null
- Why did you remove the "generator"? HOT 1
- Login when registerig HOT 1
- "Remember Me" functionality HOT 2
- How to redirect to a page if the login fails?
- Cannot find module when files are pulled from repo HOT 1
- issue with sails 0.12.14
- Error out of the box HOT 4
- warn: Action middleware (POLICY: passport) was bound to a target `auth/*` that doesn't match any registered actions. HOT 2
- Argon2 Support?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sails-auth.