summaryrefslogtreecommitdiff
path: root/src/api/client_server/session.rs
diff options
context:
space:
mode:
authorTimo Kösters <timo@koesters.xyz>2023-08-10 17:01:56 +0000
committerTimo Kösters <timo@koesters.xyz>2023-08-10 17:01:56 +0000
commit0c2cfda3ae923d9e922d5edf379e4d8976a52d4e (patch)
treea8a8ecddf12f8ea183fc8f9948d8483648b9e187 /src/api/client_server/session.rs
parent53f14a2c4c216b529cc63137d8704573197aed19 (diff)
parent4bf8ee1f7481a222efe87235fa400f6cd14ebd11 (diff)
downloadconduit-0c2cfda3ae923d9e922d5edf379e4d8976a52d4e.zip
Merge branch 'next' into 'master'v0.6.0
Merge remote-tracking branch 'origin/next' See merge request famedly/conduit!538
Diffstat (limited to 'src/api/client_server/session.rs')
-rw-r--r--src/api/client_server/session.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs
index 64c0072..5ce62af 100644
--- a/src/api/client_server/session.rs
+++ b/src/api/client_server/session.rs
@@ -9,7 +9,7 @@ use ruma::{
UserId,
};
use serde::Deserialize;
-use tracing::info;
+use tracing::{info, warn};
#[derive(Debug, Deserialize)]
struct Claims {
@@ -26,6 +26,7 @@ pub async fn get_login_types_route(
) -> Result<get_login_types::v3::Response> {
Ok(get_login_types::v3::Response::new(vec![
get_login_types::v3::LoginType::Password(Default::default()),
+ get_login_types::v3::LoginType::ApplicationService(Default::default()),
]))
}
@@ -51,6 +52,7 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
let username = if let UserIdentifier::UserIdOrLocalpart(user_id) = identifier {
user_id.to_lowercase()
} else {
+ warn!("Bad login type: {:?}", &body.login_info);
return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type."));
};
let user_id =
@@ -103,7 +105,27 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
));
}
}
+ login::v3::LoginInfo::ApplicationService(login::v3::ApplicationService { identifier }) => {
+ if !body.from_appservice {
+ return Err(Error::BadRequest(
+ ErrorKind::Forbidden,
+ "Forbidden login type.",
+ ));
+ };
+ let username = if let UserIdentifier::UserIdOrLocalpart(user_id) = identifier {
+ user_id.to_lowercase()
+ } else {
+ return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type."));
+ };
+ let user_id =
+ UserId::parse_with_server_name(username, services().globals.server_name())
+ .map_err(|_| {
+ Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid.")
+ })?;
+ user_id
+ }
_ => {
+ warn!("Unsupported or unknown login type: {:?}", &body.login_info);
return Err(Error::BadRequest(
ErrorKind::Unknown,
"Unsupported login type.",