1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! `POST /_matrix/identity/*/account/register`
//!
//! Exchanges an OpenID token from the homeserver for an access token to access the identity server.

pub mod v2 {
    //! `/v2/` ([spec])
    //!
    //! [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2accountregister

    use std::time::Duration;

    use ruma_common::{
        api::{request, response, Metadata},
        authentication::TokenType,
        metadata, OwnedServerName,
    };

    const METADATA: Metadata = metadata! {
        method: POST,
        rate_limited: false,
        authentication: None,
        history: {
            1.0 => "/_matrix/identity/v2/account/register",
        }
    };

    /// Request type for the `register_account` endpoint.
    #[request]
    pub struct Request {
        /// An access token the consumer may use to verify the identity of the person who generated
        /// the token.
        ///
        /// This is given to the federation API `GET /openid/userinfo` to verify the user's
        /// identity.
        pub access_token: String,

        /// The string `Bearer`.
        pub token_type: TokenType,

        /// The homeserver domain the consumer should use when attempting to verify the user's
        /// identity.
        pub matrix_server_name: OwnedServerName,

        /// The number of seconds before this token expires and a new one must be generated.
        #[serde(with = "ruma_common::serde::duration::secs")]
        pub expires_in: Duration,
    }

    /// Response type for the `register_account` endpoint.
    #[response]
    pub struct Response {
        /// An opaque string representing the token to authenticate future requests to the identity
        /// server with.
        pub token: String,
    }

    impl Request {
        /// Creates a new `Request` with the given parameters.
        pub fn new(
            access_token: String,
            token_type: TokenType,
            matrix_server_name: OwnedServerName,
            expires_in: Duration,
        ) -> Self {
            Self { access_token, token_type, matrix_server_name, expires_in }
        }
    }

    impl Response {
        /// Creates an empty `Response`.
        pub fn new(token: String) -> Self {
            Self { token }
        }
    }
}