From 0c8bc294c16a496dc4b1529c1d6e341da26bc2e9 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 4 Feb 2017 09:36:28 -0800 Subject: [PATCH] oauth work around for 10.3.3 security features which resolves issue #11 --- assets/.assets.index | 3 ++- assets/StreamTab.qml | 10 ++++++++++ assets/WebViewSheet.qml | 26 ++++++++++++++++++++++++++ config.pri | 1 + src/Pnut.cpp | 12 ++++++++++++ src/Pnut.h | 2 ++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 assets/WebViewSheet.qml diff --git a/assets/.assets.index b/assets/.assets.index index 638cb9d..fda23e3 100644 --- a/assets/.assets.index +++ b/assets/.assets.index @@ -1,5 +1,5 @@ 1 -45 +46 AboutPage.qml AppCover.qml LoginSheet.qml @@ -45,3 +45,4 @@ icons/sign-out.png icons/star-o.png icons/star.png StreamTab.qml +WebViewSheet.qml diff --git a/assets/StreamTab.qml b/assets/StreamTab.qml index 50a9fdc..9c4ccef 100644 --- a/assets/StreamTab.qml +++ b/assets/StreamTab.qml @@ -212,6 +212,9 @@ NavigationPane { pnut.sendPost(text) } }, + WebViewSheet { + id: webViewSheet + }, QTimer { id: timer interval: 30000 @@ -272,12 +275,19 @@ NavigationPane { onAuthorizationReceived: { console.log("-- THIS --") + webViewSheet.close() closeLogin() pnut.getStream(endpoint, Pnut.STREAM_OLDER); timer.start(); console.log("__Should be closed now") } + onOpenBrowser: { + //console.log("-- open browser --") + webViewSheet.url = url + webViewSheet.open() + } + onFollowSuccess: update_user_page(user) onUnfollowSuccess: update_user_page(user) diff --git a/assets/WebViewSheet.qml b/assets/WebViewSheet.qml new file mode 100644 index 0000000..cf92efc --- /dev/null +++ b/assets/WebViewSheet.qml @@ -0,0 +1,26 @@ +import bb.cascades 1.4 + +Sheet { + peekEnabled: false + property alias url: webview.url + Page { + ScrollView { + scrollViewProperties.pinchToZoomEnabled: true + scrollViewProperties.scrollMode: ScrollMode.Both + WebView { + id: webview + settings.zoomToFitEnabled: true + + onUrlChanged: { + //console.log("::" + url) + // Workaround for 10.3.3 + if (url.toString().match(/http\:\/\/.*#access_token\=/i)) { + //console.log("Matched url: " + url.toString()); + webview.stop(); + webview.url = url.toString(); + } + } + } + } + } +} \ No newline at end of file diff --git a/config.pri b/config.pri index dc11b65..097379d 100644 --- a/config.pri +++ b/config.pri @@ -78,6 +78,7 @@ config_pri_assets { $$quote($$BASEDIR/assets/ThreadPage.qml) \ $$quote($$BASEDIR/assets/UserItem.qml) \ $$quote($$BASEDIR/assets/UserPage.qml) \ + $$quote($$BASEDIR/assets/WebViewSheet.qml) \ $$quote($$BASEDIR/assets/icons/at.png) \ $$quote($$BASEDIR/assets/icons/bell-slash.png) \ $$quote($$BASEDIR/assets/icons/bell.png) \ diff --git a/src/Pnut.cpp b/src/Pnut.cpp index 7ad1cfc..5fa1456 100644 --- a/src/Pnut.cpp +++ b/src/Pnut.cpp @@ -51,6 +51,11 @@ Pnut::Pnut() Q_ASSERT(conn_req); + bool brw_req = connect(oauthManager, SIGNAL(openBrowser(QUrl)), + this, SLOT(onOpenBrowser(QUrl))); + + Q_ASSERT(brw_req); + qDebug() << "Pnut created, I am life."; } @@ -519,3 +524,10 @@ void Pnut::getFollowing(QString uid) req_map[++req_id] = ":following"; getRequest(url, parameters, req_id); } + +void Pnut::onOpenBrowser(QUrl url) +{ + qDebug() << "_onOpenBrowser_"; + qDebug() << url; + emit openBrowser(url); +} diff --git a/src/Pnut.h b/src/Pnut.h index 4c1db5f..7e7fdf8 100644 --- a/src/Pnut.h +++ b/src/Pnut.h @@ -93,6 +93,7 @@ public slots: void onRequestReady(QByteArray data); void onAuthorizedRequestReady(QByteArray data, int id); void onAuthorizationReceived(QString token, QString verifier); + void onOpenBrowser(QUrl url); Q_SIGNALS: void authorizationRequired(); @@ -108,6 +109,7 @@ Q_SIGNALS: void postReceived(QVariantMap post); void userStreamReceived(QVariantList stream); void userListReceived(QVariantList users); + void openBrowser(QUrl url); private: static const QString PNUT_API_ROOT;