Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod get_details;
pub mod is_user_admin;
pub mod list_joined_rooms;
pub mod list_users;
pub mod login_as_a_user;
pub mod reset_password;

use ruma::{thirdparty::ThirdPartyIdentifier, SecondsSinceUnixEpoch};
Expand Down
3 changes: 3 additions & 0 deletions src/users/login_as_a_user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Different versions of the endpoint to log in as a user.

pub mod v1;
47 changes: 47 additions & 0 deletions src/users/login_as_a_user/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! [POST /_synapse/admin/v1/users/:user_id/login](https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#login-as-a-user)

use ruma::{
api::{metadata, request, response, Metadata},
UserId,
};

const METADATA: Metadata = metadata! {
method: POST,
rate_limited: false,
authentication: AccessToken,
history: {
unstable => "/_synapse/admin/v1/users/:user_id/login",
}
};

#[request]
pub struct Request<'a> {
/// User to log in as.
#[ruma_api(path)]
pub user_id: &'a UserId,

/// Optional: Integer UNIX timestamp in milliseconds for when the access token should expire.
/// If not specified, the returned access token does not expire.
#[serde(default, skip_serializing_if = "Option::is_none")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serde(default) is implied for Option<_> typed fields.

pub valid_until_ms: Option<u64>,
}

#[response]
pub struct Response {
/// An opaque access token string, that can be used to control the user.
pub access_token: String,
}

impl<'a> Request<'a> {
/// Creates an `Request` with the given user ID.
pub fn new(user_id: &'a UserId, valid_until_ms: Option<u64>) -> Self {
Self { user_id, valid_until_ms }
}
}

impl Response {
/// Creates a `Response` with the given admin flag.
pub fn new(access_token: String) -> Self {
Self { access_token }
}
}