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.
This commit is contained in:
Stephen Legge 2013-01-05 01:49:33 -05:00
parent 40e87f1768
commit b5a3639083
2 changed files with 21 additions and 7 deletions

View file

@ -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) {

View file

@ -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