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/>.
22 #include "kqoauthrequest_xauth_p.h"
23 #include "kqoauthrequest_xauth.h"
26 * Private d_ptr implementations.
28 KQOAuthRequest_XAuthPrivate::KQOAuthRequest_XAuthPrivate()
33 KQOAuthRequest_XAuthPrivate::~KQOAuthRequest_XAuthPrivate()
38 * Public implementations.
40 KQOAuthRequest_XAuth::KQOAuthRequest_XAuth(QObject *parent) :
41 KQOAuthRequest(parent),
42 d_ptr(new KQOAuthRequest_XAuthPrivate)
46 bool KQOAuthRequest_XAuth::isValid() const {
47 // An xAuth can never request temporary credentials.
48 if (requestType() == KQOAuthRequest::TemporaryCredentials) {
49 qWarning() << "XAuth request cannot be of type KQOAuthRequest::TemporaryCredentials. Aborting.";
53 // Access token must always be retrieved using the POST HTTP method.
54 if (requestType() == KQOAuthRequest::AccessToken
55 && httpMethod() != KQOAuthRequest::POST) {
57 qWarning() << "Access tokens must be fetched using the POST HTTP method. Aborting.";
62 if (!xauth_parameters_set) {
63 qWarning() << "No XAuth parameters set. Aborting.";
67 // And then check the validity of the XAuth request.
68 // Provided by the base class as a protected method for us.
69 return validateXAuthRequest();
72 void KQOAuthRequest_XAuth::setXAuthLogin(const QString &username,
73 const QString &password) {
75 if (username.isEmpty() || password.isEmpty()) {
76 qWarning() << "Username or password cannot be empty. Aborting.";
80 xauth_parameters_set = true;
82 KQOAuthParameters xauthParams;
83 xauthParams.insert("x_auth_username", username);
84 xauthParams.insert("x_auth_password", password);
85 xauthParams.insert("x_auth_mode", "client_auth");
87 setAdditionalParameters(xauthParams);