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
10
namespace
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.
16
class
QUOTIENT_API
GetLoginFlowsJob
:
public
BaseJob
{
17
public
:
18
// Inner data structures
19
20
struct
QUOTIENT_API
LoginFlow
{
21
//! The login type. This is supplied as the `type` when
22
//! logging in.
23
QString
type
;
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
33
bool
delegatedOidcCompatibility
{
false
};
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.
44
static
QUrl
makeRequestUrl
(
const
HomeserverData
&
hsData
);
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
52
inline
auto
collectResponse
(
const
GetLoginFlowsJob* job) {
return
job->flows(); }
53
54
template
<>
55
struct
QUOTIENT_API
JsonObjectConverter
<
GetLoginFlowsJob
::
LoginFlow
> {
56
static
void
fillFrom
(
const
QJsonObject
&
jo
,
GetLoginFlowsJob
::
LoginFlow
&
result
)
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
),
61
result
.
delegatedOidcCompatibility
);
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).
78
class
QUOTIENT_API
LoginJob
:
public
BaseJob
{
79
public
:
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
,
110
const
std
::
optional
<
UserIdentifier
>&
identifier
=
std
::
nullopt
,
111
const
QString
&
password
= {},
const
QString
&
token
= {},
112
const
QString
&
deviceId
= {},
const
QString
&
initialDeviceDisplayName
= {},
113
std
::
optional
<
bool
>
refreshToken
=
std
::
nullopt
);
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.
135
std
::
optional
<
int
>
expiresInMs
()
const
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.
148
std
::
optional
<
DiscoveryInformation
>
wellKnown
()
const
149
{
150
return
loadFromJson
<
std
::
optional
<
DiscoveryInformation
>>(
"well_known"_L1
);
151
}
152
153
struct
Response
{
154
//! The fully-qualified Matrix ID for the account.
155
QString
userId
{};
156
157
//! An access token for the account.
158
//! This access token can then be used to authorize other requests.
159
QString
accessToken
{};
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.
164
QString
refreshToken
{};
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.
172
std
::
optional
<
int
>
expiresInMs
{};
173
174
//! ID of the logged-in device. Will be the same as the
175
//! corresponding parameter in the request, if one was specified.
176
QString
deviceId
{};
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.
182
std
::
optional
<
DiscoveryInformation
>
wellKnown
{};
183
};
184
};
185
186
template
<
std
::
derived_from
<
LoginJob
>
JobT
>
187
constexpr
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
Quotient::GetLoginFlowsJob
Get the supported login types to authenticate users.
Definition
login.h:16
Quotient::LoginJob
Authenticates the user.
Definition
login.h:78
Quotient
Definition
accountregistry.h:13
Quotient::collectResponse
auto collectResponse(const GetAccountDataJob *job)
Definition
account-data.h:59
QUOTIENT_API
#define QUOTIENT_API
Definition
quotient_export.h:22
Quotient
csapi
login.h
Generated by
1.9.8