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