libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
login.h
Go to the documentation of this file.
1// THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
2
3#pragma once
4
5#include <Quotient/csapi/definitions/user_identifier.h>
6#include <Quotient/csapi/definitions/wellknown/full.h>
7
8#include <Quotient/jobs/basejob.h>
9
10namespace Quotient {
11
12//! \brief Get the supported login types to authenticate users
13//!
14//! Gets the homeserver's supported login types to authenticate users. Clients
15//! should pick one of these and supply it as the `type` when logging in.
17public:
18 // Inner data structures
19
21 //! The login type. This is supplied as the `type` when
22 //! logging in.
24
25 //! If `type` is `m.login.token`, an optional field to indicate
26 //! to the unauthenticated client that the homeserver supports
27 //! the [`POST /login/get_token`](/client-server-api/#post_matrixclientv1loginget_token)
28 //! endpoint. Note that supporting the endpoint does not
29 //! necessarily indicate that the user attempting to log in will
30 //! be able to generate such a token.
31 bool getLoginToken{ false };
32
34 };
35
36 // Construction/destruction
37
38 explicit GetLoginFlowsJob();
39
40 //! \brief Construct a URL without creating a full-fledged job object
41 //!
42 //! This function can be used when a URL for GetLoginFlowsJob
43 //! is necessary but the job itself isn't.
45
46 // Result properties
47
48 //! The homeserver's supported login types
49 QVector<LoginFlow> flows() const { return loadFromJson<QVector<LoginFlow>>("flows"_L1); }
50};
51
52inline auto collectResponse(const GetLoginFlowsJob* job) { return job->flows(); }
53
54template <>
57 {
58 fillFromJson(jo.value("type"_L1), result.type);
59 fillFromJson(jo.value("get_login_token"_L1), result.getLoginToken);
60 fillFromJson(jo.value("org.matrix.msc3824.delegated_oidc_compatibility"_L1),
62 }
63};
64
65//! \brief Authenticates the user.
66//!
67//! Authenticates the user, and issues an access token they can
68//! use to authorize themself in subsequent requests.
69//!
70//! If the client does not supply a `device_id`, the server must
71//! auto-generate one.
72//!
73//! The returned access token must be associated with the `device_id`
74//! supplied by the client or generated by the server. The server may
75//! invalidate any access token previously associated with that device. See
76//! [Relationship between access tokens and
77//! devices](/client-server-api/#relationship-between-access-tokens-and-devices).
79public:
80 //! \param type
81 //! The login type being used.
82 //!
83 //! This must be a type returned in one of the flows of the
84 //! response of the [`GET /login`](/client-server-api/#get_matrixclientv3login)
85 //! endpoint, like `m.login.password` or `m.login.token`.
86 //!
87 //!
88 //! \param password
89 //! Required when `type` is `m.login.password`. The user's
90 //! password.
91 //!
92 //! \param token
93 //! Required when `type` is `m.login.token`. Part of Token-based login.
94 //!
95 //! \param deviceId
96 //! ID of the client device. If this does not correspond to a
97 //! known client device, a new device will be created. The given
98 //! device ID must not be the same as a
99 //! [cross-signing](/client-server-api/#cross-signing) key ID.
100 //! The server will auto-generate a device_id
101 //! if this is not specified.
102 //!
103 //! \param initialDeviceDisplayName
104 //! A display name to assign to the newly-created device. Ignored
105 //! if `device_id` corresponds to a known device.
106 //!
107 //! \param refreshToken
108 //! If true, the client supports refresh tokens.
109 explicit LoginJob(const QString& type,
111 const QString& password = {}, const QString& token = {},
112 const QString& deviceId = {}, const QString& initialDeviceDisplayName = {},
114
115 // Result properties
116
117 //! The fully-qualified Matrix ID for the account.
118 QString userId() const { return loadFromJson<QString>("user_id"_L1); }
119
120 //! An access token for the account.
121 //! This access token can then be used to authorize other requests.
122 QString accessToken() const { return loadFromJson<QString>("access_token"_L1); }
123
124 //! A refresh token for the account. This token can be used to
125 //! obtain a new access token when it expires by calling the
126 //! `/refresh` endpoint.
127 QString refreshToken() const { return loadFromJson<QString>("refresh_token"_L1); }
128
129 //! The lifetime of the access token, in milliseconds. Once
130 //! the access token has expired a new access token can be
131 //! obtained by using the provided refresh token. If no
132 //! refresh token is provided, the client will need to re-log in
133 //! to obtain a new access token. If not given, the client can
134 //! assume that the access token will not expire.
136 {
137 return loadFromJson<std::optional<int>>("expires_in_ms"_L1);
138 }
139
140 //! ID of the logged-in device. Will be the same as the
141 //! corresponding parameter in the request, if one was specified.
142 QString deviceId() const { return loadFromJson<QString>("device_id"_L1); }
143
144 //! Optional client configuration provided by the server. If present,
145 //! clients SHOULD use the provided object to reconfigure themselves,
146 //! optionally validating the URLs within. This object takes the same
147 //! form as the one returned from .well-known autodiscovery.
149 {
150 return loadFromJson<std::optional<DiscoveryInformation>>("well_known"_L1);
151 }
152
153 struct Response {
154 //! The fully-qualified Matrix ID for the account.
156
157 //! An access token for the account.
158 //! This access token can then be used to authorize other requests.
160
161 //! A refresh token for the account. This token can be used to
162 //! obtain a new access token when it expires by calling the
163 //! `/refresh` endpoint.
165
166 //! The lifetime of the access token, in milliseconds. Once
167 //! the access token has expired a new access token can be
168 //! obtained by using the provided refresh token. If no
169 //! refresh token is provided, the client will need to re-log in
170 //! to obtain a new access token. If not given, the client can
171 //! assume that the access token will not expire.
173
174 //! ID of the logged-in device. Will be the same as the
175 //! corresponding parameter in the request, if one was specified.
177
178 //! Optional client configuration provided by the server. If present,
179 //! clients SHOULD use the provided object to reconfigure themselves,
180 //! optionally validating the URLs within. This object takes the same
181 //! form as the one returned from .well-known autodiscovery.
183 };
184};
185
186template <std::derived_from<LoginJob> JobT>
187constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> LoginJob::Response {
188 return { j->userId(), j->accessToken(), j->refreshToken(),
189 j->expiresInMs(), j->deviceId(), j->wellKnown() };
190};
191
192} // namespace Quotient
Get the supported login types to authenticate users.
Definition login.h:16
Authenticates the user.
Definition login.h:78
auto collectResponse(const GetAccountDataJob *job)
#define QUOTIENT_API