Replies: 1 comment
-
The crux of the problem is that the closure passed to But, #[rocket::async_trait]
impl<'r> FromRequest<'r> for Authenticated {
type Error = ();
async fn from_request(request: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
let keys: Vec<_> = request.headers().get("Authorization").collect();
let db: Database = try_outcome!(request.guard::<Database>().await);
if keys.len() != 1 {
return Outcome::Failure((Status::Unauthorized, ()));
}
let key: Vec<_> = keys[0].split(' ').collect();
if key.len() == 2 && is_bearer(&key) {
let token_value = match uuid::Uuid::parse_str(key[1]) {
Ok(uuid) => uuid,
Err(_) => {
return Outcome::Failure((Status::BadRequest, ()));
}
};
// fn validate_token(token: Result<OAuth2TokenNullableModel, OAuth2TokenRetrievalError>, p: &PgConnection,) -> request::Outcome<Authenticated, ()>
db.run(|connection| validate_token(retrieve_token_by_value(&token_value, &connection), &connection)).await
}
Outcome::Failure((Status::BadRequest, ()))
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
General information
Rocket version: 0.5.0-rc.1
OS: Ubuntu 20.04.2 LTS
Cargo version: cargo 1.54.0-nightly (44456677b 2021-06-12)
Problem
Hello, I am trying to migrate my work project from Rocket 0.4 to Rocket 0.5 but I encountered what I would say is a bug but I'm not sure if I am doing this correctly.
I have a custom guard in my API which implement
FromRequest
. It retrieves theAuthorization
header in the request header, and valid the token with the help of my database fairing (PostgreSQL) get byrequest.guard
. When I want to retrieve the pool from my database I use theasync run()
method crated by thedatabase
macro ofrocket_sync_db_pools
. In the lambda passed as argument of the method I do all my token validation operations and return arequest::Outcome
in consequence.Expectation
Returning
db.run(|pool| {...})
shouldn't be a problem since it returns the same type as defined infrom_request
.Reality
The code does not compile and
rustc
shows an error of lifetime.Sample
Code:
Compilation error:
I don't really understand this error but it wasn't a problem before
0.5
, thank you for your consideration.Beta Was this translation helpful? Give feedback.
All reactions