Permalink
Browse files

Update

  • Loading branch information...
1 parent 21ce26a commit 98426ae24a4ec77e3c232ae55f25da76c9e5ec0c @kylefowler kylefowler committed Mar 23, 2012
View
@@ -1,4 +1,5 @@
-#About the oauth library for BlackBerry 10
+About the oauth library for BlackBerry 10
+==========================================
This is a OAuth library built for the Cascades development framework for BlackBerry 10. It is a fork and BlackBerry specific implementation of the KQOauth library that can be found here http://www.gitorious.org/kqoauth under the LGPL license.
This library supports both OAuth1 and OAuth2 authorization flow and authorized requests.
View
@@ -0,0 +1,56 @@
+/**
+ * KQOAuth - An OAuth authentication library for Qt.
+ *
+ * Author: Johan Paul (johan.paul@d-pointer.com)
+ * http://www.d-pointer.com
+ *
+ * KQOAuth is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KQOAuth is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <QtDebug>
+
+#include "kqoauth2request_p.h"
+#include "kqoauth2request.h"
+
+/**
+ * Private d_ptr implementations.
+ */
+KQOAuth2Request_Private::KQOAuth2Request_Private()
+{
+
+}
+
+KQOAuth2Request_Private::~KQOAuth2Request_Private()
+{
+}
+
+/**
+ * Public implementations.
+ */
+KQOAuth2Request::KQOAuth2Request(QObject *parent) :
+ KQOAuthRequest(parent),
+ d_ptr(new KQOAuth2Request_Private)
+{
+}
+
+bool KQOAuth2Request::isValid() const {
+ // Access token must always be retrieved using the POST HTTP method.
+ // And then check the validity of the XAuth request.
+ // Provided by the base class as a protected method for us.
+ return validateOauth2Request();
+}
+
+void KQOAuth2Request::initRequest(KQOAuthRequest::RequestType type, const QUrl &requestEndpoint) {
+ KQOAuthRequest::initRequest(type,requestEndpoint);
+ setRequestOAuthMethod(KQOAuthRequest::OAUTH2);
+}
View
@@ -0,0 +1,45 @@
+/**
+ * KQOAuth - An OAuth authentication library for Qt.
+ *
+ * Author: Johan Paul (johan.paul@d-pointer.com)
+ * http://www.d-pointer.com
+ *
+ * KQOAuth is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KQOAuth is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KQOAUTH2REQUEST_H
+#define KQOAUTH2REQUEST_H
+
+#include "kqoauthrequest.h"
+#include "kqoauthrequest_1.h"
+
+class KQOAuth2Request_Private;
+class KQOAUTH_EXPORT KQOAuth2Request : public KQOAuthRequest
+{
+ Q_OBJECT
+public:
+ KQOAuth2Request(QObject *parent = 0);
+
+ /**
+ * These methods can be overridden in child classes which are different types of
+ * OAuth requests.
+ */
+ // Validate the request of this type.
+ bool isValid() const;
+ void initRequest(KQOAuthRequest::RequestType type, const QUrl &requestEndpoint);
+
+private:
+ KQOAuth2Request_Private * const d_ptr;
+};
+
+#endif // KQOAUTHREQUEST_XAUTH_H
View
@@ -0,0 +1,14 @@
+#ifndef KQOAUTH2REQUEST_P_H
+#define KQOAUTH2REQUEST_P_H
+
+#include "kqoauthglobals.h"
+
+class KQOAuthRequest;
+class KQOAUTH_EXPORT KQOAuth2Request_Private
+{
+public:
+ KQOAuth2Request_Private();
+ ~KQOAuth2Request_Private();
+};
+
+#endif // KQOAUTHREQUEST_XAUTH_P_H
@@ -0,0 +1,110 @@
+/**
+ * KQOAuth - An OAuth authentication library for Qt.
+ *
+ * Author: Johan Paul (johan.paul@d-pointer.com)
+ * http://www.d-pointer.com
+ *
+ * KQOAuth is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KQOAuth is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <QTcpSocket>
+#include <QStringList>
+#include <QUrl>
+
+#include "kqoauthauthreplyserver.h"
+#include "kqoauthauthreplyserver_p.h"
+
+KQOAuthAuthReplyServerPrivate::KQOAuthAuthReplyServerPrivate(KQOAuthAuthReplyServer *parent):
+ q_ptr(parent)
+{
+
+}
+
+KQOAuthAuthReplyServerPrivate::~KQOAuthAuthReplyServerPrivate()
+{
+
+}
+
+void KQOAuthAuthReplyServerPrivate::onIncomingConnection() {
+ Q_Q(KQOAuthAuthReplyServer);
+
+ socket = q->nextPendingConnection();
+ connect(socket, SIGNAL(readyRead()),
+ this, SLOT(onBytesReady()), Qt::UniqueConnection);
+}
+
+void KQOAuthAuthReplyServerPrivate::onBytesReady() {
+ Q_Q(KQOAuthAuthReplyServer);
+
+ QByteArray reply;
+ QByteArray content;
+ content.append("<HTML><h1>Account authorized, go ahead back to the tumblr app and start your experience!</h1></HTML>");
+
+ reply.append("HTTP/1.0 200 OK \r\n");
+ reply.append("Content-Type: text/html; charset=\"utf-8\"\r\n");
+ reply.append(QString("Content-Length: %1\r\n").arg(content.size()));
+ reply.append("\r\n");
+ reply.append(content);
+ socket->write(reply);
+
+ QByteArray data = socket->readAll();
+ QMultiMap<QString, QString> queryParams = parseQueryParams(&data);
+
+ socket->disconnectFromHost();
+ q->close();
+ emit q->verificationReceived(queryParams);
+}
+
+QMultiMap<QString, QString> KQOAuthAuthReplyServerPrivate::parseQueryParams(QByteArray *data) {
+ QString splitGetLine = QString(*data).split("\r\n").first(); // Retrieve the first line with query params.
+ splitGetLine.remove("GET "); // Clean the line from GET
+ splitGetLine.remove("HTTP/1.1"); // From HTTP
+ splitGetLine.remove("\r\n"); // And from rest.
+ splitGetLine.prepend("http://localhost"); // Now, make it a URL
+
+ QUrl getTokenUrl(splitGetLine);
+ QList< QPair<QString, QString> > tokens = getTokenUrl.queryItems(); // Ask QUrl to do our work.
+
+ QMultiMap<QString, QString> queryParams;
+ QPair<QString, QString> tokenPair;
+ foreach (tokenPair, tokens) {
+ queryParams.insert(tokenPair.first.trimmed(), tokenPair.second.trimmed());
+ }
+
+ return queryParams;
+}
+
+
+
+KQOAuthAuthReplyServer::KQOAuthAuthReplyServer(QObject *parent) :
+ QTcpServer(parent),
+ d_ptr( new KQOAuthAuthReplyServerPrivate(this) )
+{
+ Q_D(KQOAuthAuthReplyServer);
+
+ connect(this, SIGNAL(newConnection()),
+ d, SLOT(onIncomingConnection()));
+}
+
+KQOAuthAuthReplyServer::~KQOAuthAuthReplyServer()
+{
+ delete d_ptr;
+}
+
+
+void KQOAuthAuthReplyServer::setSuccessHtmlFile(QString filePath) {
+ Q_D(KQOAuthAuthReplyServer);
+ d->localFile = filePath;
+}
+
+
@@ -0,0 +1,48 @@
+/**
+ * KQOAuth - An OAuth authentication library for Qt.
+ *
+ * Author: Johan Paul (johan.paul@d-pointer.com)
+ * http://www.d-pointer.com
+ *
+ * KQOAuth is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KQOAuth is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KQOAUTHAUTHREPLYSERVER_H
+#define KQOAUTHAUTHREPLYSERVER_H
+
+#include <QTcpServer>
+
+#include "kqoauthglobals.h"
+
+class KQOAuthAuthReplyServerPrivate;
+class KQOAUTH_EXPORT KQOAuthAuthReplyServer : public QTcpServer
+{
+ Q_OBJECT
+public:
+ explicit KQOAuthAuthReplyServer(QObject *parent);
+ ~KQOAuthAuthReplyServer();
+ void setSuccessHtmlFile(QString filePath);
+
+Q_SIGNALS:
+ void verificationReceived(QMultiMap<QString, QString>);
+
+
+private:
+ KQOAuthAuthReplyServerPrivate * const d_ptr;
+ Q_DECLARE_PRIVATE(KQOAuthAuthReplyServer);
+ Q_DISABLE_COPY(KQOAuthAuthReplyServer);
+
+
+};
+
+#endif // KQOAUTHAUTHREPLYSERVER_H
@@ -0,0 +1,47 @@
+/**
+ * KQOAuth - An OAuth authentication library for Qt.
+ *
+ * Author: Johan Paul (johan.paul@d-pointer.com)
+ * http://www.d-pointer.com
+ *
+ * KQOAuth is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KQOAuth is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
+ */
+// Note this class shouldn't be copied or used and the implementation might change later.
+#ifndef KQOAUTHAUTHREPLYSERVER_P_H
+#define KQOAUTHAUTHREPLYSERVER_P_H
+
+#include "kqoauthauthreplyserver.h"
+#include <QMultiMap>
+#include <QString>
+
+class KQOAUTH_EXPORT KQOAuthAuthReplyServerPrivate: public QObject
+{
+ Q_OBJECT
+public:
+ KQOAuthAuthReplyServerPrivate( KQOAuthAuthReplyServer * parent );
+ ~KQOAuthAuthReplyServerPrivate();
+ QMultiMap<QString, QString> parseQueryParams(QByteArray *sdata);
+
+public Q_SLOTS:
+ void onIncomingConnection();
+ void onBytesReady();
+
+public:
+ KQOAuthAuthReplyServer * q_ptr;
+ Q_DECLARE_PUBLIC(KQOAuthAuthReplyServer);
+ QTcpSocket *socket;
+ QString localFile;
+};
+
+#endif // KQOAUTHAUTHREPLYSERVER_P_H
View
@@ -0,0 +1,48 @@
+/**
+ * KQOAuth - An OAuth authentication library for Qt.
+ *
+ * Author: Johan Paul (johan.paul@d-pointer.com)
+ * http://www.d-pointer.com
+ *
+ * KQOAuth is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KQOAuth is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with KQOAuth. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef KQOAUTHGLOBALS_H
+#define KQOAUTHGLOBALS_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(KQOAUTH)
+# define KQOAUTH_EXPORT Q_DECL_EXPORT
+#else
+# define KQOAUTH_EXPORT Q_DECL_IMPORT
+#endif
+
+//////////// Static constant definitions ///////////
+const QString OAUTH_KEY_CONSUMER("oauth_consumer");
+const QString OAUTH_KEY_CONSUMER_KEY("oauth_consumer_key");
+const QString OAUTH_KEY_TOKEN("oauth_token");
+const QString OAUTH_KEY_TOKEN_SECRET("oauth_token_secret");
+const QString OAUTH_KEY_SIGNATURE_METHOD("oauth_signature_method");
+const QString OAUTH_KEY_TIMESTAMP("oauth_timestamp");
+const QString OAUTH_KEY_NONCE("oauth_nonce");
+const QString OAUTH_KEY_SIGNATURE("oauth_signature");
+const QString OAUTH_KEY_CALLBACK("oauth_callback");
+const QString OAUTH_KEY_VERIFIER("oauth_verifier");
+const QString OAUTH_KEY_VERSION("oauth_version");
+const QString OAUTH2_KEY_CLIENT_ID("client_id");
+const QString OAUTH2_KEY_CLIENT_SECRET("client_secret");
+const QString OAUTH2_KEY_REDIRECT_URI("redirect_uri");
+const QString OAUTH2_KEY_RESPONSE_TYPE("response_type");
+
+#endif // KQOAUTHGLOBALS_H
Oops, something went wrong.

0 comments on commit 98426ae

Please sign in to comment.