aboutsummaryrefslogtreecommitdiff
path: root/src/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/auth.rs b/src/auth.rs
index b1a743da..809ef9fd 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -615,7 +615,6 @@ pub struct AdminHeaders {
pub device: Device,
pub user: User,
pub org_user_type: UserOrgType,
- pub client_version: Option<String>,
pub ip: ClientIp,
}
@@ -625,14 +624,12 @@ impl<'r> FromRequest<'r> for AdminHeaders {
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
let headers = try_outcome!(OrgHeaders::from_request(request).await);
- let client_version = request.headers().get_one("Bitwarden-Client-Version").map(String::from);
if headers.org_user_type >= UserOrgType::Admin {
Outcome::Success(Self {
host: headers.host,
device: headers.device,
user: headers.user,
org_user_type: headers.org_user_type,
- client_version,
ip: headers.ip,
})
} else {
@@ -900,3 +897,24 @@ impl<'r> FromRequest<'r> for WsAccessTokenHeader {
})
}
}
+
+pub struct ClientVersion(pub semver::Version);
+
+#[rocket::async_trait]
+impl<'r> FromRequest<'r> for ClientVersion {
+ type Error = &'static str;
+
+ async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
+ let headers = request.headers();
+
+ let Some(version) = headers.get_one("Bitwarden-Client-Version") else {
+ err_handler!("No Bitwarden-Client-Version header provided")
+ };
+
+ let Ok(version) = semver::Version::parse(version) else {
+ err_handler!("Invalid Bitwarden-Client-Version header provided")
+ };
+
+ Outcome::Success(ClientVersion(version))
+ }
+}