tvallotton / rocket_auth

An implementation for an authentication API for Rocket applications.
https://docs.rs/rocket_auth/
Apache License 2.0
73 stars 35 forks source link

User FromRequest not found with git rocket and TLS #35

Open ecashin opened 2 years ago

ecashin commented 2 years ago

Hi. I'm hoping to implement a simple web app that includes user authentication and uses TLS. I am using a Cargo.toml that allows me to use TLS with Rocket:

[package]
name = "vhallway"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.56"
rocket = { version = "0.5.0-rc.1", git = "https://github.com/SergioBenitez/Rocket.git", features = ["mtls", "secrets", "tls"] }
rocket_auth = { version = "0.4.0", features = ["tokio-postgres"] }

I have a minimal main.rs:

#[macro_use]
extern crate rocket;

use rocket_auth::User;

#[get("/user")]
fn user_info(user: User) -> String {
    format!("{:?}", user)
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![user_info])
}

... and see the following error when doing cargo build:

error[E0277]: the trait bound `User: FromRequest<'_>` is not satisfied
 --> src/main.rs:7:20
  |
7 | fn user_info(user: User) -> String {
  |                    ^^^^ the trait `FromRequest<'_>` is not implemented for `User`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `vhallway` due to previous error

But cargo test --doc works on rocket_auth cloned from github, and the User doctest is similar to my usage.

ecashin commented 2 years ago

I also have a Rocket.toml based on the TLS example in Rocket, with certs I generated with the script there, but I don't think that's affecting the compile stage.

SpootDev commented 2 years ago

I'd try removing 'git = "https://github.com/SergioBenitez/Rocket.git",' from your dependency line.

ecashin commented 2 years ago

I'd try removing 'git = "https://github.com/SergioBenitez/Rocket.git",' from your dependency line.

Yes, thanks, I did try that, but without that you cannot use the crates that make TLS work:

ecashin@dell-Latitude-E6420:~/src/rust/vhallway$ cargo build
error: failed to select a version for `rocket`.
    ... required by package `vhallway v0.1.0 (/home/ecashin/src/rust/vhallway)`
versions that meet the requirements `^0.5.0-rc.1` are: 0.5.0-rc.1

the package `vhallway` depends on `rocket`, with features: `mtls` but `rocket` does not have these features.

failed to select a version for `rocket` which could resolve this conflict
ecashin@dell-Latitude-E6420:~/src/rust/vhallway$ 
SpootDev commented 2 years ago

Ah, I'll be using nginx proxy for ssl........so, I've not played with mtls feature. I get the same error when I just tried to enable mtls in my app as well.

SpootDev commented 2 years ago

Rocket RC2 just dropped a few days ago......might fix your tls issue.

Zusier commented 2 years ago

Removing git and upgrading to rc2 fixed an issue for me with a similar error relating to "FromRequest" traits. 👍

ecashin commented 2 years ago

Removing git and upgrading to rc2 fixed a similar issue for me with a similar issue relating to "FromRequest" traits. +1

Thanks for the info. I will try to stop using caddy and see if it works now.