| 1 |
/** |
| 2 |
* KQOAuth - An OAuth authentication library for Qt. |
| 3 |
* |
| 4 |
* Author: Johan Paul ([email protected]) |
| 5 |
* http://www.johanpaul.com |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 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. |
| 16 |
* |
| 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/>. |
| 19 |
*/ |
| 20 |
#include <QtDebug> |
| 21 |
|
| 22 |
#include "kqoauthrequest_xauth_p.h" |
| 23 |
#include "kqoauthrequest_xauth.h" |
| 24 |
|
| 25 |
/** |
| 26 |
* Private d_ptr implementations. |
| 27 |
*/ |
| 28 |
KQOAuthRequest_XAuthPrivate::KQOAuthRequest_XAuthPrivate() |
| 29 |
{ |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
KQOAuthRequest_XAuthPrivate::~KQOAuthRequest_XAuthPrivate() |
| 34 |
{ |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Public implementations. |
| 39 |
*/ |
| 40 |
KQOAuthRequest_XAuth::KQOAuthRequest_XAuth(QObject *parent) : |
| 41 |
KQOAuthRequest(parent), |
| 42 |
d_ptr(new KQOAuthRequest_XAuthPrivate) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 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."; |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
// Access token must always be retrieved using the POST HTTP method. |
| 54 |
if (requestType() == KQOAuthRequest::AccessToken |
| 55 |
&& httpMethod() != KQOAuthRequest::POST) { |
| 56 |
|
| 57 |
qWarning() << "Access tokens must be fetched using the POST HTTP method. Aborting."; |
| 58 |
|
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
if (!xauth_parameters_set) { |
| 63 |
qWarning() << "No XAuth parameters set. Aborting."; |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 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(); |
| 70 |
} |
| 71 |
|
| 72 |
void KQOAuthRequest_XAuth::setXAuthLogin(const QString &username, |
| 73 |
const QString &password) { |
| 74 |
|
| 75 |
if (username.isEmpty() || password.isEmpty()) { |
| 76 |
qWarning() << "Username or password cannot be empty. Aborting."; |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
xauth_parameters_set = true; |
| 81 |
|
| 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"); |
| 86 |
|
| 87 |
setAdditionalParameters(xauthParams); |
| 88 |
} |
| 89 |
|