From b5a3639083d2f96a44d50d3025c3fb916ffc09e2 Mon Sep 17 00:00:00 2001 From: Stephen Legge Date: Sat, 5 Jan 2013 01:49:33 -0500 Subject: [PATCH] Split user authorization into two parts One function to get the url if your app wants to launch the authorization in its own way, another that keeps the same functionality of launching in the default browser. --- oauth/kqoauthmanager.cpp | 22 +++++++++++++++------- oauth/kqoauthmanager.h | 6 ++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/oauth/kqoauthmanager.cpp b/oauth/kqoauthmanager.cpp index f903ef0..2caa029 100644 --- a/oauth/kqoauthmanager.cpp +++ b/oauth/kqoauthmanager.cpp @@ -441,19 +441,19 @@ void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QStr navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0); } -void KQOAuthManager::getUserAuthorization(QUrl authorizationEndpoint) { +QUrl KQOAuthManager::getUserAuthorizationUrl(QUrl authorizationEndpoint) { Q_D(KQOAuthManager); if (!d->hasTemporaryToken) { qWarning() << "No temporary tokens retreieved. Cannot get user authorization."; d->error = KQOAuthManager::RequestUnauthorized; - return; + return QUrl(); } if (!authorizationEndpoint.isValid()) { qWarning() << "Authorization endpoint not valid. Cannot proceed."; d->error = KQOAuthManager::RequestEndpointError; - return; + return QUrl(); } d->error = KQOAuthManager::NoError; @@ -462,11 +462,19 @@ void KQOAuthManager::getUserAuthorization(QUrl authorizationEndpoint) { QUrl openWebPageUrl(authorizationEndpoint.toString(), QUrl::StrictMode); openWebPageUrl.addQueryItem(tokenParam.first, tokenParam.second); - // Open the user's default browser to the resource authorization page provided - // by the service. - qDebug() << openWebPageUrl.toString(); - navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0); + return openWebPageUrl; +} + +void KQOAuthManager::getUserAuthorization(QUrl authorizationEndpoint) { + QUrl openWebPageUrl = getUserAuthorizationUrl(authorizationEndpoint); + + if(!openWebPageUrl.isEmpty()) { + // Open the user's default browser to the resource authorization page provided + // by the service. + + navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0); + } } void KQOAuthManager::getUserAccessTokens(QUrl accessTokenEndpoint) { diff --git a/oauth/kqoauthmanager.h b/oauth/kqoauthmanager.h index ec0d47c..6778626 100644 --- a/oauth/kqoauthmanager.h +++ b/oauth/kqoauthmanager.h @@ -106,6 +106,12 @@ public: */ void setSuccessHtmlFile(QString filePath); + /** + * This is a convenience API for authorizing the user. + * The call will verify that a temporary token was received and return the url that the user needs to + * use to authorize the app, it will not open the user's default browser. + */ + QUrl getUserAuthorizationUrl(QUrl authorizationEndpoint); /** * This is a convenience API for authorizing the user. * The call will open the user's default browser, setup a local HTTP server and parse the reply from the