1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QOAUTH2DEVICEAUTHORIZATIONFLOW_H
5#define QOAUTH2DEVICEAUTHORIZATIONFLOW_H
6
7#include <QtNetworkAuth/qoauthglobal.h>
8
9#ifndef QT_NO_HTTP
10
11#include <QtNetworkAuth/qabstractoauth2.h>
12
13QT_BEGIN_NAMESPACE
14
15class QDateTime;
16class QUrl;
17class QString;
18class QNetworkAccessManager;
19
20class QOAuth2DeviceAuthorizationFlowPrivate;
21class Q_OAUTH_EXPORT QOAuth2DeviceAuthorizationFlow : public QAbstractOAuth2
22{
23 Q_OBJECT
24 Q_PROPERTY(QString userCode READ userCode NOTIFY userCodeChanged FINAL)
25 Q_PROPERTY(QUrl verificationUrl READ verificationUrl NOTIFY verificationUrlChanged FINAL)
26 Q_PROPERTY(QUrl completeVerificationUrl READ completeVerificationUrl
27 NOTIFY completeVerificationUrlChanged FINAL)
28 Q_PROPERTY(bool polling READ isPolling NOTIFY pollingChanged FINAL)
29 Q_PROPERTY(QDateTime userCodeExpirationAt READ userCodeExpirationAt
30 NOTIFY userCodeExpirationAtChanged FINAL)
31
32public:
33 QOAuth2DeviceAuthorizationFlow();
34 explicit QOAuth2DeviceAuthorizationFlow(QObject *parent);
35 explicit QOAuth2DeviceAuthorizationFlow(QNetworkAccessManager *manager,
36 QObject *parent = nullptr);
37 ~QOAuth2DeviceAuthorizationFlow() override;
38
39 QString userCode() const;
40 QUrl verificationUrl() const;
41 QUrl completeVerificationUrl() const;
42 bool isPolling() const;
43 QDateTime userCodeExpirationAt() const;
44
45public Q_SLOTS:
46 void grant() override;
47 bool startTokenPolling();
48 void stopTokenPolling();
49
50Q_SIGNALS:
51 void authorizeWithUserCode(const QUrl &verificationUrl, const QString &userCode,
52 const QUrl &completeVerificationUrl);
53 void userCodeChanged(const QString &userCode);
54 void verificationUrlChanged(const QUrl &verificationUrl);
55 void completeVerificationUrlChanged(const QUrl &completeVerificationUrl);
56 void pollingChanged(bool polling);
57 void userCodeExpirationAtChanged(const QDateTime &expiration);
58
59protected:
60 bool event(QEvent *event) override;
61
62protected Q_SLOTS:
63 void refreshTokensImplementation() QT7_ONLY(override);
64
65private:
66 Q_DISABLE_COPY_MOVE(QOAuth2DeviceAuthorizationFlow)
67 Q_DECLARE_PRIVATE(QOAuth2DeviceAuthorizationFlow)
68};
69
70QT_END_NAMESPACE
71
72#endif // QT_NO_HTTP
73
74#endif // QOAUTH2DEVICEAUTHORIZATIONFLOW_H
75

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