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

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