1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Network Auth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#ifndef QOAUTH1_H
31#define QOAUTH1_H
32
33#ifndef QT_NO_HTTP
34
35#include <QtNetworkAuth/qoauthglobal.h>
36#include <QtNetworkAuth/qabstractoauth.h>
37
38#include <QtNetwork/qnetworkaccessmanager.h>
39
40QT_BEGIN_NAMESPACE
41
42class QOAuth1Private;
43class Q_OAUTH_EXPORT QOAuth1: public QAbstractOAuth
44{
45 Q_OBJECT
46
47public:
48 enum class SignatureMethod {
49 Hmac_Sha1,
50 Rsa_Sha1,
51 PlainText
52 };
53
54 Q_ENUM(SignatureMethod)
55
56 explicit QOAuth1(QObject *parent = nullptr);
57 explicit QOAuth1(QNetworkAccessManager *manager,
58 QObject *parent = nullptr);
59
60 QOAuth1(const QString &clientIdentifier,
61 const QString &clientSharedSecret,
62 QNetworkAccessManager *manager,
63 QObject *parent = nullptr);
64
65 QString clientSharedSecret() const;
66 void setClientSharedSecret(const QString &clientSharedSecret);
67 QPair<QString, QString> clientCredentials() const;
68 void setClientCredentials(const QPair<QString, QString> &clientCredentials);
69 void setClientCredentials(const QString &clientIdentifier, const QString &clientSharedSecret);
70
71 // Token credentials: https://tools.ietf.org/html/rfc5849#section-2.3
72 QString tokenSecret() const;
73 void setTokenSecret(const QString &tokenSecret);
74 QPair<QString, QString> tokenCredentials() const;
75 void setTokenCredentials(const QPair<QString, QString> &tokenCredentials);
76 void setTokenCredentials(const QString &token, const QString &tokenSecret);
77
78 // Temporary Credentials: https://tools.ietf.org/html/rfc5849#section-2.1
79 QUrl temporaryCredentialsUrl() const;
80 void setTemporaryCredentialsUrl(const QUrl &url);
81
82 // Token Credentials: https://tools.ietf.org/html/rfc5849#section-2.3
83 QUrl tokenCredentialsUrl() const;
84 void setTokenCredentialsUrl(const QUrl &url);
85
86 // Signature method: https://tools.ietf.org/html/rfc5849#section-3.4
87 SignatureMethod signatureMethod() const;
88 void setSignatureMethod(SignatureMethod value);
89
90public:
91 QNetworkReply *head(const QUrl &url, const QVariantMap &parameters = QVariantMap()) override;
92 QNetworkReply *get(const QUrl &url, const QVariantMap &parameters = QVariantMap()) override;
93
94 QNetworkReply *post(const QUrl &url, const QVariantMap &parameters = QVariantMap()) override;
95 QNetworkReply *put(const QUrl &url, const QVariantMap &parameters = QVariantMap()) override;
96 QNetworkReply *deleteResource(const QUrl &url,
97 const QVariantMap &parameters = QVariantMap()) override;
98
99public Q_SLOTS:
100 void grant() override;
101 void continueGrantWithVerifier(const QString &verifier);
102
103Q_SIGNALS:
104 void signatureMethodChanged(QOAuth1::SignatureMethod method);
105 void clientSharedSecretChanged(const QString &credential);
106 void tokenSecretChanged(const QString &token);
107 void temporaryCredentialsUrlChanged(const QUrl &url);
108 void tokenCredentialsUrlChanged(const QUrl &url);
109
110protected:
111 QNetworkReply *requestTemporaryCredentials(QNetworkAccessManager::Operation operation,
112 const QUrl &url,
113 const QVariantMap &parameters = QVariantMap());
114
115 QNetworkReply *requestTokenCredentials(QNetworkAccessManager::Operation operation,
116 const QUrl &url,
117 const QPair<QString, QString> &temporaryToken,
118 const QVariantMap &parameters = QVariantMap());
119
120 void setup(QNetworkRequest *request,
121 const QVariantMap &signingParameters,
122 QNetworkAccessManager::Operation operation);
123 void setup(QNetworkRequest *request,
124 const QVariantMap &signingParameters,
125 const QByteArray &operationVerb);
126
127 static QByteArray nonce();
128 static QByteArray generateAuthorizationHeader(const QVariantMap &oauthParams);
129
130private:
131 Q_DISABLE_COPY(QOAuth1)
132 Q_DECLARE_PRIVATE(QOAuth1)
133};
134
135QT_END_NAMESPACE
136
137#endif // QT_NO_HTTP
138
139#endif // QOAUTH1_H
140

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