Skip to main content

arminius_server_client/handlers/
account.rs

1// SPDX-FileCopyrightText: 2025 BWI GmbH
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! Implements APIs for account management from the matrix spec
6
7mod tests;
8
9use arminius_lib_component::{Component, ServerState, ruma_requests::ArminiusResponse};
10use axum::{Router, routing::get};
11use ruma::api::client::account::{get_3pids, whoami};
12
13use crate::client_request::AuthenticatedClientRequest;
14
15/// Handler for `GET /_matrix/client/v3/account/3pid` (See
16/// <https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3account3pid>).
17///
18/// Gets the list of third-party identifiers that the homeserver has associated
19/// with the user’s account.
20///
21/// NOTE: It is always empty because the server does not support 3PID.
22async fn get_3pids_handler(
23	AuthenticatedClientRequest(_claims, _request): AuthenticatedClientRequest<
24		get_3pids::v3::Request,
25	>,
26) -> ArminiusResponse<get_3pids::v3::Response> {
27	get_3pids::v3::Response::new(vec![]).into()
28}
29
30/// Handler for `GET /_matrix/client/v3/account/whoami` (See
31/// <https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3accountwhoami>).
32///
33/// Gets information about the owner of the given access token.
34async fn whoami_handler(
35	AuthenticatedClientRequest(claims, _request): AuthenticatedClientRequest<whoami::v3::Request>,
36) -> ArminiusResponse<whoami::v3::Response> {
37	let mut resp = whoami::v3::Response::new(claims.user_id, false);
38	resp.device_id = Some(claims.device_id);
39
40	resp.into()
41}
42
43/// Component implementing endpoints for account management
44#[derive(Debug)]
45pub struct AccountComponent;
46
47impl Component for AccountComponent {
48	fn router() -> Router<ServerState> {
49		Router::new()
50			.route("/_matrix/client/v3/account/3pid", get(get_3pids_handler))
51			.route("/_matrix/client/v3/account/whoami", get(whoami_handler))
52	}
53}