Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-04 02:18:00 +01:00
Add separate host-only fromrequest handler
Dieser Commit ist enthalten in:
Ursprung
ce62e898c3
Commit
2969e87b52
1 geänderte Dateien mit 26 neuen und 5 gelöschten Zeilen
31
src/auth.rs
31
src/auth.rs
|
@ -222,13 +222,12 @@ use crate::db::{
|
||||||
DbConn,
|
DbConn,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Headers {
|
pub struct Host {
|
||||||
pub host: String,
|
pub host: String
|
||||||
pub device: Device,
|
|
||||||
pub user: User,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for Headers {
|
|
||||||
|
impl<'a, 'r> FromRequest<'a, 'r> for Host {
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
|
|
||||||
fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
|
fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
|
||||||
|
@ -262,6 +261,28 @@ impl<'a, 'r> FromRequest<'a, 'r> for Headers {
|
||||||
format!("{}://{}", protocol, host)
|
format!("{}://{}", protocol, host)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Outcome::Success(Host { host })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Headers {
|
||||||
|
pub host: String,
|
||||||
|
pub device: Device,
|
||||||
|
pub user: User,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'r> FromRequest<'a, 'r> for Headers {
|
||||||
|
type Error = &'static str;
|
||||||
|
|
||||||
|
fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
|
||||||
|
let headers = request.headers();
|
||||||
|
|
||||||
|
let host = match Host::from_request(request) {
|
||||||
|
Outcome::Forward(_) => return Outcome::Forward(()),
|
||||||
|
Outcome::Failure(f) => return Outcome::Failure(f),
|
||||||
|
Outcome::Success(host) => host.host,
|
||||||
|
};
|
||||||
|
|
||||||
// Get access_token
|
// Get access_token
|
||||||
let access_token: &str = match headers.get_one("Authorization") {
|
let access_token: &str = match headers.get_one("Authorization") {
|
||||||
Some(a) => match a.rsplit("Bearer ").next() {
|
Some(a) => match a.rsplit("Bearer ").next() {
|
||||||
|
|
Laden …
In neuem Issue referenzieren