1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QOAUTH1_H |
5 | #define QOAUTH1_H |
6 | |
7 | #include <QtNetworkAuth/qoauthglobal.h> |
8 | |
9 | #ifndef QT_NO_HTTP |
10 | |
11 | #include <QtNetworkAuth/qabstractoauth.h> |
12 | |
13 | #include <QtNetwork/qnetworkaccessmanager.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QOAuth1Private; |
18 | class Q_OAUTH_EXPORT QOAuth1: public QAbstractOAuth |
19 | { |
20 | Q_OBJECT |
21 | |
22 | public: |
23 | enum class SignatureMethod { |
24 | Hmac_Sha1, |
25 | Rsa_Sha1, |
26 | PlainText |
27 | }; |
28 | |
29 | Q_ENUM(SignatureMethod) |
30 | |
31 | explicit QOAuth1(QObject *parent = nullptr); |
32 | explicit QOAuth1(QNetworkAccessManager *manager, |
33 | QObject *parent = nullptr); |
34 | |
35 | QOAuth1(const QString &clientIdentifier, |
36 | const QString &clientSharedSecret, |
37 | QNetworkAccessManager *manager, |
38 | QObject *parent = nullptr); |
39 | |
40 | QString clientSharedSecret() const; |
41 | void setClientSharedSecret(const QString &clientSharedSecret); |
42 | std::pair<QString, QString> clientCredentials() const; |
43 | void setClientCredentials(const std::pair<QString, QString> &clientCredentials); |
44 | void setClientCredentials(const QString &clientIdentifier, const QString &clientSharedSecret); |
45 | |
46 | // Token credentials: https://tools.ietf.org/html/rfc5849#section-2.3 |
47 | QString tokenSecret() const; |
48 | void setTokenSecret(const QString &tokenSecret); |
49 | std::pair<QString, QString> tokenCredentials() const; |
50 | void setTokenCredentials(const std::pair<QString, QString> &tokenCredentials); |
51 | void setTokenCredentials(const QString &token, const QString &tokenSecret); |
52 | |
53 | // Temporary Credentials: https://tools.ietf.org/html/rfc5849#section-2.1 |
54 | QUrl temporaryCredentialsUrl() const; |
55 | void setTemporaryCredentialsUrl(const QUrl &url); |
56 | |
57 | // Token Credentials: https://tools.ietf.org/html/rfc5849#section-2.3 |
58 | QUrl tokenCredentialsUrl() const; |
59 | void setTokenCredentialsUrl(const QUrl &url); |
60 | |
61 | // Signature method: https://tools.ietf.org/html/rfc5849#section-3.4 |
62 | SignatureMethod signatureMethod() const; |
63 | void setSignatureMethod(SignatureMethod value); |
64 | |
65 | void prepareRequest(QNetworkRequest *request, const QByteArray &verb, |
66 | const QByteArray &body = QByteArray()) override; |
67 | |
68 | QNetworkReply *(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; |
69 | QNetworkReply *get(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; |
70 | |
71 | QNetworkReply *post(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; |
72 | QNetworkReply *put(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; |
73 | QNetworkReply *deleteResource(const QUrl &url, |
74 | const QVariantMap ¶meters = QVariantMap()) override; |
75 | |
76 | public Q_SLOTS: |
77 | void grant() override; |
78 | void continueGrantWithVerifier(const QString &verifier); |
79 | |
80 | Q_SIGNALS: |
81 | void signatureMethodChanged(QOAuth1::SignatureMethod method); |
82 | void clientSharedSecretChanged(const QString &credential); |
83 | void tokenSecretChanged(const QString &token); |
84 | void temporaryCredentialsUrlChanged(const QUrl &url); |
85 | void tokenCredentialsUrlChanged(const QUrl &url); |
86 | |
87 | protected: |
88 | QNetworkReply *requestTemporaryCredentials(QNetworkAccessManager::Operation operation, |
89 | const QUrl &url, |
90 | const QVariantMap ¶meters = QVariantMap()); |
91 | |
92 | QNetworkReply *requestTokenCredentials(QNetworkAccessManager::Operation operation, |
93 | const QUrl &url, |
94 | const std::pair<QString, QString> &temporaryToken, |
95 | const QVariantMap ¶meters = QVariantMap()); |
96 | |
97 | void setup(QNetworkRequest *request, |
98 | const QVariantMap &signingParameters, |
99 | QNetworkAccessManager::Operation operation); |
100 | void setup(QNetworkRequest *request, |
101 | const QVariantMap &signingParameters, |
102 | const QByteArray &operationVerb); |
103 | |
104 | static QByteArray nonce(); |
105 | static QByteArray (const QVariantMap &oauthParams); |
106 | |
107 | private: |
108 | Q_DISABLE_COPY(QOAuth1) |
109 | Q_DECLARE_PRIVATE(QOAuth1) |
110 | }; |
111 | |
112 | QT_END_NAMESPACE |
113 | |
114 | #endif // QT_NO_HTTP |
115 | |
116 | #endif // QOAUTH1_H |
117 | |