ruma_client_api/account/request_openid_token.rs
1//! `POST /_matrix/client/*/user/{userId}/openid/request_token`
2//!
3//! Request an OpenID 1.0 token to verify identity with a third party.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/v1.18/client-server-api/#post_matrixclientv3useruseridopenidrequest_token
9
10 use std::time::Duration;
11
12 use ruma_common::{
13 OwnedServerName, OwnedUserId,
14 api::{auth_scheme::AccessToken, request, response},
15 authentication::TokenType,
16 metadata,
17 };
18
19 metadata! {
20 method: POST,
21 rate_limited: true,
22 authentication: AccessToken,
23 history: {
24 1.0 => "/_matrix/client/r0/user/{user_id}/openid/request_token",
25 1.1 => "/_matrix/client/v3/user/{user_id}/openid/request_token",
26 }
27 }
28
29 /// Request type for the `request_openid_token` endpoint.
30 #[request]
31 pub struct Request {
32 /// User ID of authenticated user.
33 #[ruma_api(path)]
34 pub user_id: OwnedUserId,
35 }
36
37 /// Response type for the `request_openid_token` endpoint.
38 #[response]
39 pub struct Response {
40 /// Access token for verifying user's identity.
41 pub access_token: String,
42
43 /// Access token type.
44 pub token_type: TokenType,
45
46 /// Homeserver domain for verification of user's identity.
47 pub matrix_server_name: OwnedServerName,
48
49 /// Seconds until token expiration.
50 #[serde(with = "ruma_common::serde::duration::secs")]
51 pub expires_in: Duration,
52 }
53
54 impl Request {
55 /// Creates a new `Request` with the given user ID.
56 pub fn new(user_id: OwnedUserId) -> Self {
57 Self { user_id }
58 }
59 }
60
61 impl Response {
62 /// Creates a new `Response` with the given access token, token type, server name and
63 /// expiration duration.
64 pub fn new(
65 access_token: String,
66 token_type: TokenType,
67 matrix_server_name: OwnedServerName,
68 expires_in: Duration,
69 ) -> Self {
70 Self { access_token, token_type, matrix_server_name, expires_in }
71 }
72 }
73}