improvement: better appservice compatibility and optimizations

This commit is contained in:
Timo Kösters 2021-02-06 15:27:43 +01:00
parent fd3fb3a7ed
commit 6924dfc8ea
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
9 changed files with 270 additions and 207 deletions

View file

@ -45,7 +45,7 @@ where
http::request::Request<std::vec::Vec<u8>>,
>>::Error: std::fmt::Debug,
{
type Error = (); // TODO: Better error handling
type Error = ();
type Owned = Data;
type Borrowed = Self::Owned;
@ -82,7 +82,9 @@ where
registration
.get("as_token")
.and_then(|as_token| as_token.as_str())
.map_or(false, |as_token| token.as_deref() == Some(as_token))
.map_or(false, |as_token| {
dbg!(token.as_deref()) == dbg!(Some(as_token))
})
}) {
match T::METADATA.authentication {
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
@ -105,7 +107,8 @@ where
);
if !db.users.exists(&user_id).unwrap() {
return Failure((Status::Unauthorized, ()));
// Forbidden
return Failure((Status::raw(580), ()));
}
// TODO: Check if appservice is allowed to be that user
@ -119,15 +122,15 @@ where
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
if let Some(token) = token {
match db.users.find_from_token(&token).unwrap() {
// TODO: M_UNKNOWN_TOKEN
None => return Failure((Status::Unauthorized, ())),
// Unknown Token
None => return Failure((Status::raw(581), ())),
Some((user_id, device_id)) => {
(Some(user_id), Some(device_id.into()), false)
}
}
} else {
// TODO: M_MISSING_TOKEN
return Failure((Status::Unauthorized, ()));
// Missing Token
return Failure((Status::raw(582), ()));
}
}
AuthScheme::ServerSignatures => (None, None, false),
@ -163,7 +166,7 @@ where
}),
Err(e) => {
warn!("{:?}", e);
Failure((Status::BadRequest, ()))
Failure((Status::raw(583), ()))
}
}
})