2 * KQOAuth - An OAuth authentication library for Qt.
4 * Author: Johan Paul (johan.paul@d-pointer.com)
5 * http://www.d-pointer.com
7 * KQOAuth is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * KQOAuth is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef KQOAUTHREQUEST_H
21 #define KQOAUTHREQUEST_H
27 #include "kqoauthglobals.h"
29 typedef QMultiMap<QString, QString> KQOAuthParameters;
31 class KQOAuthRequestPrivate;
32 class KQOAUTH_EXPORT KQOAuthRequest : public QObject
36 explicit KQOAuthRequest(QObject *parent = 0);
40 TemporaryCredentials = 0,
45 enum RequestSignatureMethod {
51 enum RequestHttpMethod {
57 * These methods can be overridden in child classes which are different types of
60 // Validate the request of this type.
61 virtual bool isValid() const;
64 * These methods are OAuth request type specific and not overridden in child
66 * NOTE: Refactorting still a TODO
68 // Initialize the request of this type.
69 void initRequest(KQOAuthRequest::RequestType type, const QUrl &requestEndpoint);
71 void setConsumerKey(const QString &consumerKey);
72 void setConsumerSecretKey(const QString &consumerSecretKey);
74 // Mandatory methods for acquiring a request token
75 void setCallbackUrl(const QUrl &callbackUrl);
77 // Mandator methods for acquiring a access token
78 void setTokenSecret(const QString &tokenSecret);
79 void setToken(const QString &token);
80 void setVerifier(const QString &verifier);
82 // Request signature method to use - HMAC_SHA1 currently only supported
83 void setSignatureMethod(KQOAuthRequest::RequestSignatureMethod = KQOAuthRequest::HMAC_SHA1);
85 // Request's HTTP method.
86 void setHttpMethod(KQOAuthRequest::RequestHttpMethod = KQOAuthRequest::POST);
87 KQOAuthRequest::RequestHttpMethod httpMethod() const;
89 // Sets the timeout for this request. If the timeout expires, signal "requestTimedout" will be
90 // emitted from the manager.
91 // 0 = If set to zero, timeout is disabled.
92 // TODO: Do we need some request ID now?
93 void setTimeout(int timeoutMilliseconds);
95 // Additional optional parameters to the request.
96 void setAdditionalParameters(const KQOAuthParameters &additionalParams);
97 KQOAuthParameters additionalParameters() const;
98 QList<QByteArray> requestParameters(); // This will return all request's parameters in the raw format given
99 // to the QNetworkRequest.
100 QByteArray requestBody() const; // This will return the POST body as given to the QNetworkRequest.
102 KQOAuthRequest::RequestType requestType() const;
103 QUrl requestEndpoint() const;
105 void setContentType(const QString &contentType);
106 QString contentType();
108 void setRawData(const QByteArray &rawData);
109 QByteArray rawData();
113 // Enable verbose debug output for request content.
114 void setEnableDebugOutput(bool enabled);
117 // This signal is emited if the request is not completed before the request's timeout
118 // value has expired.
119 void requestTimedout();
122 bool validateXAuthRequest() const;
125 KQOAuthRequestPrivate * const d_ptr;
126 Q_DECLARE_PRIVATE(KQOAuthRequest);
127 Q_DISABLE_COPY(KQOAuthRequest);
129 // These classes are only for the internal use of KQOAuthManager so it can
130 // work with the opaque request.
131 QString consumerKeyForManager() const;
132 QString consumerKeySecretForManager() const;
133 QUrl callbackUrlForManager() const;
135 // This method is for timeout handling by the KQOAuthManager.
136 void requestTimerStart();
137 void requestTimerStop();
139 friend class KQOAuthManager;
141 friend class Ut_KQOAuth;
145 #endif // KQOAUTHREQUEST_H