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:
parent
40e87f1768
commit
b5a3639083
2 changed files with 21 additions and 7 deletions
|
@ -441,19 +441,19 @@ void KQOAuthManager::getOauth2UserAuthorization(QUrl authorizationEndpoint, QStr
|
||||||
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
|
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KQOAuthManager::getUserAuthorization(QUrl authorizationEndpoint) {
|
QUrl KQOAuthManager::getUserAuthorizationUrl(QUrl authorizationEndpoint) {
|
||||||
Q_D(KQOAuthManager);
|
Q_D(KQOAuthManager);
|
||||||
|
|
||||||
if (!d->hasTemporaryToken) {
|
if (!d->hasTemporaryToken) {
|
||||||
qWarning() << "No temporary tokens retreieved. Cannot get user authorization.";
|
qWarning() << "No temporary tokens retreieved. Cannot get user authorization.";
|
||||||
d->error = KQOAuthManager::RequestUnauthorized;
|
d->error = KQOAuthManager::RequestUnauthorized;
|
||||||
return;
|
return QUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!authorizationEndpoint.isValid()) {
|
if (!authorizationEndpoint.isValid()) {
|
||||||
qWarning() << "Authorization endpoint not valid. Cannot proceed.";
|
qWarning() << "Authorization endpoint not valid. Cannot proceed.";
|
||||||
d->error = KQOAuthManager::RequestEndpointError;
|
d->error = KQOAuthManager::RequestEndpointError;
|
||||||
return;
|
return QUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
d->error = KQOAuthManager::NoError;
|
d->error = KQOAuthManager::NoError;
|
||||||
|
@ -462,12 +462,20 @@ void KQOAuthManager::getUserAuthorization(QUrl authorizationEndpoint) {
|
||||||
QUrl openWebPageUrl(authorizationEndpoint.toString(), QUrl::StrictMode);
|
QUrl openWebPageUrl(authorizationEndpoint.toString(), QUrl::StrictMode);
|
||||||
openWebPageUrl.addQueryItem(tokenParam.first, tokenParam.second);
|
openWebPageUrl.addQueryItem(tokenParam.first, tokenParam.second);
|
||||||
|
|
||||||
|
qDebug() << openWebPageUrl.toString();
|
||||||
|
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
|
// Open the user's default browser to the resource authorization page provided
|
||||||
// by the service.
|
// by the service.
|
||||||
|
|
||||||
qDebug() << openWebPageUrl.toString();
|
|
||||||
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
|
navigator_invoke(openWebPageUrl.toString().toStdString().c_str(),0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KQOAuthManager::getUserAccessTokens(QUrl accessTokenEndpoint) {
|
void KQOAuthManager::getUserAccessTokens(QUrl accessTokenEndpoint) {
|
||||||
Q_D(KQOAuthManager);
|
Q_D(KQOAuthManager);
|
||||||
|
|
|
@ -106,6 +106,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void setSuccessHtmlFile(QString filePath);
|
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.
|
* 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
|
* The call will open the user's default browser, setup a local HTTP server and parse the reply from the
|
||||||
|
|
Loading…
Reference in a new issue