tuwunel_api/client/admin/tokens/
create.rs1use axum::extract::State;
2use synapse_admin_api::registration_tokens::create::v1 as create;
3use tuwunel_core::Result;
4
5use super::{database_token_response, token_expires};
6use crate::{Ruma, client::admin::require_admin};
7
8pub(crate) async fn admin_create_token_route(
12 State(services): State<crate::State>,
13 body: Ruma<create::Request>,
14) -> Result<create::Response> {
15 require_admin(&services, body.sender_user()).await?;
16
17 let expires = token_expires(body.uses_allowed, body.expiry_time)?;
18
19 let (token, info) = services
20 .registration_tokens
21 .create_token(
22 body.token.as_deref(),
23 body.length
24 .and_then(|length| length.try_into().ok()),
25 expires,
26 )
27 .await?;
28
29 Ok(create::Response {
30 token: database_token_response(token, &info),
31 })
32}