1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-07 17:03:01 +03:00

Add API to check localpart availability

This commit is contained in:
Quentin Gliech
2024-02-27 18:03:33 +01:00
parent 68c4bfaa11
commit 20dd5ca311
3 changed files with 71 additions and 0 deletions

View File

@@ -175,6 +175,37 @@ impl HomeserverConnection for SynapseConnection {
})
}
#[tracing::instrument(
name = "homeserver.is_localpart_available",
skip_all,
fields(
matrix.homeserver = self.homeserver,
matrix.localpart = localpart,
),
err(Display),
)]
async fn is_localpart_available(&self, localpart: &str) -> Result<bool, Self::Error> {
let mut client = self
.http_client_factory
.client("homeserver.is_localpart_available");
let request = self
.get(&format!(
"_synapse/admin/v1/username_available?username={localpart}"
))
.body(EmptyBody::new())?;
let response = client.ready().await?.call(request).await?;
match response.status() {
StatusCode::OK => Ok(true),
StatusCode::BAD_REQUEST => Ok(false),
_ => Err(anyhow::anyhow!(
"Failed to query localpart availability from Synapse"
)),
}
}
#[tracing::instrument(
name = "homeserver.provision_user",
skip_all,