libQuotient
A Qt library for building matrix clients
refresh.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/jobs/basejob.h>
6 
7 namespace Quotient {
8 
9 //! \brief Refresh an access token
10 //!
11 //! Refresh an access token. Clients should use the returned access token
12 //! when making subsequent API calls, and store the returned refresh token
13 //! (if given) in order to refresh the new access token when necessary.
14 //!
15 //! After an access token has been refreshed, a server can choose to
16 //! invalidate the old access token immediately, or can choose not to, for
17 //! example if the access token would expire soon anyways. Clients should
18 //! not make any assumptions about the old access token still being valid,
19 //! and should use the newly provided access token instead.
20 //!
21 //! The old refresh token remains valid until the new access token or refresh token
22 //! is used, at which point the old refresh token is revoked.
23 //!
24 //! Note that this endpoint does not require authentication via an
25 //! access token. Authentication is provided via the refresh token.
26 //!
27 //! Application Service identity assertion is disabled for this endpoint.
28 class QUOTIENT_API RefreshJob : public BaseJob {
29 public:
30  //! \param refreshToken
31  //! The refresh token
32  explicit RefreshJob(const QString& refreshToken);
33 
34  // Result properties
35 
36  //! The new access token to use.
37  QString accessToken() const { return loadFromJson<QString>("access_token"_L1); }
38 
39  //! The new refresh token to use when the access token needs to
40  //! be refreshed again. If not given, the old refresh token can
41  //! be re-used.
42  QString refreshToken() const { return loadFromJson<QString>("refresh_token"_L1); }
43 
44  //! The lifetime of the access token, in milliseconds. If not
45  //! given, the client can assume that the access token will not
46  //! expire.
47  std::optional<int> expiresInMs() const
48  {
49  return loadFromJson<std::optional<int>>("expires_in_ms"_L1);
50  }
51 
52  struct Response {
53  //! The new access token to use.
54  QString accessToken{};
55 
56  //! The new refresh token to use when the access token needs to
57  //! be refreshed again. If not given, the old refresh token can
58  //! be re-used.
59  QString refreshToken{};
60 
61  //! The lifetime of the access token, in milliseconds. If not
62  //! given, the client can assume that the access token will not
63  //! expire.
64  std::optional<int> expiresInMs{};
65  };
66 };
67 
68 template <std::derived_from<RefreshJob> JobT>
69 constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> RefreshJob::Response {
70  return { j->accessToken(), j->refreshToken(), j->expiresInMs() };
71 };
72 
73 } // namespace Quotient