updated to support QT5 and replaced native BlackBerry call with a signal

This commit is contained in:
Morgan McMillian 2016-10-27 12:43:03 -07:00
parent 6bc048d79d
commit cd3fa09dbc
5 changed files with 54 additions and 13 deletions

View file

@ -27,6 +27,7 @@
#include <QFile>
#include <QDir>
#include <QFileInfoList>
#include <QUrlQuery>
#include "kqoauthauthreplyserver.h"
#include "kqoauthauthreplyserver_p.h"
@ -103,7 +104,8 @@ QMultiMap<QString, QString> KQOAuthAuthReplyServerPrivate::parseQueryParams(QByt
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.
QUrlQuery qry(getTokenUrl);
QList< QPair<QString, QString> > tokens = qry.queryItems();
QMultiMap<QString, QString> queryParams;
QPair<QString, QString> tokenPair;

View file

@ -22,10 +22,10 @@
* along with KQOAuth. If not, see <http://www.gnu.org/licenses/>
*/
#include <QtCore>
#include <QUrlQuery>
#include "kqoauthmanager.h"
#include "kqoauthmanager_p.h"
#include "bps/navigator.h"
////////////// Private d_ptr implementation ////////////////
@ -219,7 +219,9 @@ void KQOAuthManager::executeRequest(KQOAuthRequest *request) {
// Take the original URL and append the query params to it.
QUrl urlWithParams = networkRequest.url();
urlWithParams.setQueryItems(urlParams);
QUrlQuery qry;
qry.setQueryItems(urlParams);
urlWithParams.setQuery(qry);
networkRequest.setUrl(urlWithParams);
// Submit the request including the params.
@ -333,7 +335,9 @@ void KQOAuthManager::executeAuthorizedRequest(KQOAuthRequest *request, int id) {
// Take the original URL and append the query params to it.
QUrl urlWithParams = networkRequest.url();
urlWithParams.setQueryItems(urlParams);
QUrlQuery qry;
qry.setQueryItems(urlParams);
urlWithParams.setQuery(qry);
networkRequest.setUrl(urlWithParams);
qDebug() << networkRequest.url();
@ -454,17 +458,20 @@ void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QStr
QString serverString = "http://localhost:";
serverString.append(QString::number(d->callbackServer->serverPort()));
QUrl openWebPageUrl(authorizationEndpoint.toString(), QUrl::StrictMode);
openWebPageUrl.addQueryItem(OAUTH2_KEY_CLIENT_ID, consumerKey);
openWebPageUrl.addQueryItem(OAUTH2_KEY_RESPONSE_TYPE, "token");
openWebPageUrl.addQueryItem(OAUTH2_KEY_REDIRECT_URI, serverString);
QUrlQuery qry;
qry.addQueryItem(OAUTH2_KEY_CLIENT_ID, consumerKey);
qry.addQueryItem(OAUTH2_KEY_RESPONSE_TYPE, "token");
qry.addQueryItem(OAUTH2_KEY_REDIRECT_URI, serverString);
if(additionalParams.size() > 0) {
QList< QPair<QString, QString> > urlParams = d->createQueryParams(additionalParams);
for(int i=0; i < urlParams.length(); i++){
openWebPageUrl.addQueryItem(urlParams[i].first, urlParams[i].second);
qry.addQueryItem(urlParams[i].first, urlParams[i].second);
}
}
openWebPageUrl.setQuery(qry);
qDebug() << openWebPageUrl.toString();
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
// navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
emit openBrowser(openWebPageUrl);
}
QUrl KQOAuthManager::getUserAuthorizationUrl(QUrl authorizationEndpoint) {
@ -486,7 +493,9 @@ QUrl KQOAuthManager::getUserAuthorizationUrl(QUrl authorizationEndpoint) {
QPair<QString, QString> tokenParam = qMakePair(QString("oauth_token"), QString(d->requestToken));
QUrl openWebPageUrl(authorizationEndpoint.toString(), QUrl::StrictMode);
openWebPageUrl.addQueryItem(tokenParam.first, tokenParam.second);
QUrlQuery qry;
qry.addQueryItem(tokenParam.first, tokenParam.second);
openWebPageUrl.setQuery(qry);
qDebug() << openWebPageUrl.toString();
return openWebPageUrl;
@ -499,7 +508,8 @@ void KQOAuthManager::getUserAuthorization(QUrl authorizationEndpoint) {
// Open the user's default browser to the resource authorization page provided
// by the service.
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
// navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
emit openBrowser(openWebPageUrl);
}
}

View file

@ -187,6 +187,8 @@ Q_SIGNALS:
// This ends the kQOAuth interactions.
void authorizedRequestDone();
void openBrowser(QUrl url);
private Q_SLOTS:
void onRequestReplyReceived( QNetworkReply *reply );
void onAuthorizedRequestReplyReceived( QNetworkReply *reply );

View file

@ -30,7 +30,7 @@
QString KQOAuthUtils::hmac_sha1(const QString &message, const QString &key)
{
QByteArray keyBytes = key.toAscii();
QByteArray keyBytes = key.toLatin1();
int keyLength; // Lenght of key word
const int blockSize = 64; // Both MD5 and SHA-1 have a block size of 64.
@ -64,7 +64,7 @@ QString KQOAuthUtils::hmac_sha1(const QString &message, const QString &key)
workArray.append(ipad, 64);
/* http://tools.ietf.org/html/rfc2104 - (3) */
workArray.append(message.toAscii());
workArray.append(message.toLatin1());
/* http://tools.ietf.org/html/rfc2104 - (4) */

27
oauth/src.pri Normal file
View file

@ -0,0 +1,27 @@
QT *= network
INCLUDEPATH += $$PWD
SOURCES += \
$$PWD/kqoauth2request.cpp \
$$PWD/kqoauthauthreplyserver.cpp \
$$PWD/kqoauthmanager.cpp \
$$PWD/kqoauthrequest_1.cpp \
$$PWD/kqoauthrequest.cpp \
$$PWD/kqoauthrequest_xauth.cpp \
$$PWD/kqoauthutils.cpp
HEADERS += \
$$PWD/kqoauth2request.h \
$$PWD/kqoauth2request_p.h \
$$PWD/kqoauthauthreplyserver.h \
$$PWD/kqoauthauthreplyserver_p.h \
$$PWD/kqoauthglobals.h \
$$PWD/kqoauthmanager.h \
$$PWD/kqoauthmanager_p.h \
$$PWD/kqoauthrequest_1.h \
$$PWD/kqoauthrequest.h \
$$PWD/kqoauthrequest_p.h \
$$PWD/kqoauthrequest_xauth.h \
$$PWD/kqoauthrequest_xauth_p.h \
$$PWD/kqoauthutils.h