ruma_identity_service_api/authentication/register.rs
1//! `POST /_matrix/identity/*/account/register`
2//!
3//! Exchanges an OpenID token from the homeserver for an access token to access the identity server.
4
5pub mod v2 {
6 //! `/v2/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2accountregister
9
10 use std::time::Duration;
11
12 use ruma_common::{
13 api::{request, response, Metadata},
14 authentication::TokenType,
15 metadata, OwnedServerName,
16 };
17
18 const METADATA: Metadata = metadata! {
19 method: POST,
20 rate_limited: false,
21 authentication: None,
22 history: {
23 1.0 => "/_matrix/identity/v2/account/register",
24 }
25 };
26
27 /// Request type for the `register_account` endpoint.
28 #[request]
29 pub struct Request {
30 /// An access token the consumer may use to verify the identity of the person who generated
31 /// the token.
32 ///
33 /// This is given to the federation API `GET /openid/userinfo` to verify the user's
34 /// identity.
35 pub access_token: String,
36
37 /// The string `Bearer`.
38 pub token_type: TokenType,
39
40 /// The homeserver domain the consumer should use when attempting to verify the user's
41 /// identity.
42 pub matrix_server_name: OwnedServerName,
43
44 /// The number of seconds before this token expires and a new one must be generated.
45 #[serde(with = "ruma_common::serde::duration::secs")]
46 pub expires_in: Duration,
47 }
48
49 /// Response type for the `register_account` endpoint.
50 #[response]
51 pub struct Response {
52 /// An opaque string representing the token to authenticate future requests to the identity
53 /// server with.
54 pub token: String,
55 }
56
57 impl Request {
58 /// Creates a new `Request` with the given parameters.
59 pub fn new(
60 access_token: String,
61 token_type: TokenType,
62 matrix_server_name: OwnedServerName,
63 expires_in: Duration,
64 ) -> Self {
65 Self { access_token, token_type, matrix_server_name, expires_in }
66 }
67 }
68
69 impl Response {
70 /// Creates an empty `Response`.
71 pub fn new(token: String) -> Self {
72 Self { token }
73 }
74 }
75}