-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authentication strategy using header parameter #1826
Comments
Hello @ericalves, thank you for starting this discussion. To be honest, authentication and authorization in LB4 is something that we haven't figured out yet, it's on our near term roadmap - see #1839.
As I understand the design of If you want to send your access token in a request header, then maybe HTTP Bearer is the strategy to use? See http://www.passportjs.org/packages/passport-http-bearer/
If I understand you correctly, you would like to re-create I believe Passport's Notice that the strategy does not make any assumptions about the way how users are stored. The application has to provide a In LB4, such callback can be implemented using function(username, password, done) {
userRepo.login(username, password)
.then(
user => done(null, user),
err => process.nextTick(() => done(err))
);
} And the class UserRepository extends DefaultCrudRepository<User, typeof User.prototype.id> {
// ...
async function login(username, password): Promise<User> {
const user = await this.findOne({where: {username}});
if (!user) return null;
// compute hash of the supplied password
const hash = await bcrypt(password, salt, etc.);
if (user.password !== password) return null;
return user;
}
} I am afraid we don't have any working example yet. I typed the code snippets above from the top of my head, they may not work out of the box. |
One more thing to consider: storing user's password together with user data in the same model (table) opens a lot of security vulnerabilities. For example:
For LB4, I would like us to explore the design where passwords are stored in their own table and a relation "user has one password" is configured (#1422 is tracking HasOne relation). We can also use "user has many password" and include a flag (a Password model property) to distinguish between the current active password and the passwords used in the past. |
@ericalves good news! We have recently updated https://github.com/strongloop/loopback4-example-shopping to show how to implement authentication using JWT tokens passed via The example is not using Where to find authentication-related parts:
I hope this answers you original question. You can subscribe to the following issues to keep track of our progress in moving the relevant bits from the shopping example to the authentication extension:
I am closing this issue as resolved. |
I'm trying to develop a small API to communicate with mine with LB3.
Now I'm dealing with authentication. I have some doubts. I implemented using the example in @ loopback/authentication.
I am not able to send my authentication hash in the header. How do I get it in the API and validate it in my provider?
One more thing .. I want to create my own strategy, replicating the same rule I use today in LB3 (using bcrypt). How should I proceed? Should I create my own Strategy or dothis at the provider? Do you have any examples of this?
The text was updated successfully, but these errors were encountered: