1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of the Network Access API. This header file may change from
10// version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QOAUTH2DEVICEAUTHORIZATIONFLOW_P_H
16#define QOAUTH2DEVICEAUTHORIZATIONFLOW_P_H
17
18#include <private/qabstractoauth2_p.h>
19
20#include <QtNetworkAuth/qoauth2deviceauthorizationflow.h>
21#include <QtNetworkAuth/qoauthglobal.h>
22
23#include <QtCore/qchronotimer.h>
24#include <QtCore/qdatetime.h>
25#include <QtCore/qpointer.h>
26#include <QtCore/qstring.h>
27
28#include <chrono>
29
30QT_BEGIN_NAMESPACE
31
32class QRestAccessManager;
33class QRestReply;
34
35class Q_AUTOTEST_EXPORT QOAuth2DeviceAuthorizationFlowPrivate : public QAbstractOAuth2Private
36{
37public:
38 Q_DECLARE_PUBLIC(QOAuth2DeviceAuthorizationFlow)
39
40 QOAuth2DeviceAuthorizationFlowPrivate(QNetworkAccessManager *manager = nullptr);
41 ~QOAuth2DeviceAuthorizationFlowPrivate() override;
42
43 void authorizationReplyFinished(QRestReply &reply);
44 void tokenReplyFinished(QRestReply &reply);
45
46 void handleTokenSuccessResponse(const QJsonObject &data);
47 void handleTokenErrorResponse(const QJsonObject &data);
48
49 void tokenAcquisitionFailed(QAbstractOAuth::Error error, const QString &errorString = {});
50
51 void setUserCode(const QString &code);
52 void setVerificationUrl(const QUrl &url);
53 void setVerificationUrlComplete(const QUrl &url);
54 void setUserCodeExpiration(const QDateTime &expiration);
55
56 bool startTokenPolling();
57 void stopTokenPolling();
58 void pollTokens();
59 bool isNextPollAfterExpiration() const;
60
61 void reset();
62 void resetCurrentTokenReply();
63 void resetCurrentAuthorizationReply();
64
65 QRestAccessManager *network();
66
67 // https://datatracker.ietf.org/doc/html/rfc8628#section-3.2
68 static inline constexpr auto defaultPollingInterval = std::chrono::seconds(5);
69 bool useAutoTestDurations = false;
70 QString userCode;
71 QString deviceCode;
72 QDateTime userCodeExpirationUtc; // When devicecode and usercode expire
73 QUrl verificationUrl;
74 QUrl completeVerificationUrl;
75 QRestAccessManager *restAccessManager = nullptr;
76 QChronoTimer tokenPollingTimer;
77 QPointer<QNetworkReply> currentAuthorizationReply;
78 QPointer<QNetworkReply> currentTokenReply;
79};
80
81QT_END_NAMESPACE
82
83#endif // QOAUTH2DEVICEAUTHORIZATIONFLOW_P_H
84

source code of qtnetworkauth/src/oauth/qoauth2deviceauthorizationflow_p.h