vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.3k stars 171 forks source link

Allow explicit authentication of `ModelAuthenticatable` types #742

Closed s-k closed 2 years ago

s-k commented 2 years ago

Types conforming to ModelAuthenticatable can be authenticated by calling authenticate() on the type. For example:

let user = try await User.authenticate(username: username, password: password, for: req)

This logs the user having the given username and password into req.auth and returns the found user. If the user is not found or the wrong password is supplied, an error will be thrown.

s-k commented 2 years ago

Is there any way I can help to get the PR reviewed? 🙂

Thanks in advance!

@gwynne @Joannis @siemensikkema @0xTim

0xTim commented 2 years ago

I'm going to throw this out to the community for comment. I'm not 100% convinced of the need for this vs just someone adding it as an extension in their project if they log in the user in multiple places.

(To be clear, this is useful and might get used but in general we don't want to add APIs for every possible use case as it adds more for us to maintain)

gwynne commented 2 years ago

I agree with @0xTim - while this is useful, it's behavior is too specific to its use case to justify including it in Fluent's public API.

s-k commented 2 years ago

I understand. Thanks for considering it.