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