loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
5.36k stars 227 forks source link

Configurable Auth Methods #680

Open thoward27 opened 3 months ago

thoward27 commented 3 months ago

Feature Request

Sometimes folks may not want to use JWT auth. I for one, prefer ProxyAuth when working on personal projects, others may want basic auth, or even an ability to disable auth in environments (a la Grafana Anonymous authentication).

Locally, I've got a generic auth middleware implementation that can be configured via the YAML file to work with different auth methods. What I have works for me- it does ProxyAuth and Anonymous auth.

I'd like to contribute what I have to this project, I think some folks may benefit from the ability to quickly change their authentication layer depending on what environment they are running in (who really has time to set up ProxyAuth for local dev??).

If the team is open to it, I'd be happy to open a PR and discuss what else would be necessary to contribute what I've written upstream.

kaplanelad commented 3 months ago

You can configure different authentication methods per environment (See the location here), but currently only for JWT. You can set the JWT location toBearer,Query, orCookie in the environment config file.

However, once you configure an authentication method, you cannot disable it in a different environment since the controller signature expects auth.

You are more than welcome to open a pull request. We look forward to discussing your suggestions there.