Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Return Invalid login message when user doesn’t exist #25

Merged
merged 4 commits into from
Jun 22, 2017

Conversation

marshallswain
Copy link
Member

@marshallswain marshallswain commented Jun 15, 2017

Will fix #10 once the test is fixed.

Includes failing test.  Fixes #10 (comment) once the test is fixed
@@ -78,7 +78,7 @@ class LocalVerifier {
const payload = { [`${this.options.entity}Id`]: id };
done(null, entity, payload);
})
.catch(error => error ? done(error) : done(null, error));
.catch(error => error ? done(error) : done(null, error, { message: 'Invalid login' }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of this we should actually just reject with an error instead of returning false on line https://github.com/feathersjs/feathers-authentication-local/blob/master/src/verifier.js#L58. What do you think?

I was initially following how passport expects results to come back but I think in reality we do want to reject with either a 404, 400, or 403 error if invalid credentials are passed in. Likely a 404 since it is during the query look up by username that we can't find a user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekryski Yeah. I wasn't sure exactly what would happen here: https://github.com/jaredhanson/passport-local/blob/master/lib/strategy.js#L81 where passport does a special check for !user, which is probably what you're talking about. I don't really understand the need to differentiate it. Why does Passport care?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for some passport strategies they respond differently based on the fail method being called vs. the error method. https://github.com/jaredhanson/passport-local/blob/master/lib/strategy.js#L81

Just trying to track it down to see if there is a difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya so I think we can go either way here. For local auth it really doesn't matter. The fail method is used more with OAuth and OpenID flows because there are more ways that the authentication can actually fail that may not be a result of bad user credentials. https://github.com/jaredhanson/passport-oauth2/blob/master/lib/strategy.js#L129

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick with your solution @marshallswain. It conforms more to what Passport advocates and also allows the developer to customize things much more. For example, how we handle fail calls: https://github.com/feathersjs/feathers-authentication/blob/master/src/hooks/authenticate.js#L60-L77

Copy link
Member

@ekryski ekryski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we get the tests passing this is good to :shipit:

@@ -78,7 +78,7 @@ class LocalVerifier {
const payload = { [`${this.options.entity}Id`]: id };
done(null, entity, payload);
})
.catch(error => error ? done(error) : done(null, error));
.catch(error => error ? done(error) : done(null, error, { message: 'Invalid login' }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick with your solution @marshallswain. It conforms more to what Passport advocates and also allows the developer to customize things much more. For example, how we handle fail calls: https://github.com/feathersjs/feathers-authentication/blob/master/src/hooks/authenticate.js#L60-L77

@sydcanem
Copy link

I'm glad something has been done on this one and I don't have to create my own verifier just to send some useful error. Btw, can I also suggest to add a debug line in https://github.com/feathersjs/feathers-authentication-local/blob/eb47d2b06184cb43c62bf0bc601ce9076cea260a/src/verifier.js#L58 like debug('Entity not found'). Invalid login is still isn't useful for development purpose.

@marshallswain
Copy link
Member Author

@sydcanem very good suggestions. I'll work that into the PR.

@sydcanem
Copy link

Thanks @marshallswain.

@marshallswain marshallswain merged commit 3fa1564 into master Jun 22, 2017
@marshallswain marshallswain deleted the better-error-message branch June 22, 2017 06:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad error message is returned for invalid credentials
4 participants