Commit 50f59a4e authored by Julius Künzel's avatar Julius Künzel
Browse files

Remove qt-oauth-lib

parent 6ce68aae
......@@ -185,7 +185,7 @@ endif()
if(Qt5WebEngineWidgets_FOUND)
message(STATUS "Found Qt5 WebEngineWidgets. You can use your Freesound.org credentials to download files")
target_compile_definitions(kdenliveLib PRIVATE -DQT5_USE_WEBENGINE)
target_link_libraries(kdenliveLib Qt5::WebEngineWidgets qt-oauth-lib)
target_link_libraries(kdenliveLib Qt5::WebEngineWidgets)
else()
message(STATUS "Qt5 WebEngineWidgets not found. You cannot use your Freesound.org credentials, only preview files can be downloaded from the Online Resources Widget")
endif()
......
add_subdirectory(kiss_fft)
add_subdirectory(media_ctrl)
add_subdirectory(qt-oauth-lib)
# Create a static library from oauth2
if(Qt5WebEngineWidgets_FOUND)
ki18n_wrap_ui(login_UI logindialog_ui.ui)
add_library(qt-oauth-lib STATIC oauth2.cpp logindialog.cpp ${login_UI})
target_link_libraries(qt-oauth-lib Qt5::WebEngineWidgets KF5::I18n KF5::ConfigGui)
target_compile_definitions(qt-oauth-lib PRIVATE -DQT5_USE_WEBENGINE)
endif()
/********************************************************************************************************
* Copyright (C) 2015 Roger Morton (ttguy1@gmail.com)
*
* Purpose: implements client access to freesound.org using ver2 of the freesound API.
*
* Based on code at https://code.google.com/p/qt-oauth-lib/
* Which is Qt Library created by Integrated Computer Solutions, Inc. (ICS)
* to provide OAuth2.0 for the Google API.
*
* Licence: GNU Lesser General Public License
* http://www.gnu.org/licenses/lgpl.html
* This version of the GNU Lesser General Public License incorporates the terms
* and conditions of version 3 of the GNU General Public License http://www.gnu.org/licenses/gpl-3.0-standalone.html
* supplemented by the additional permissions listed at http://www.gnu.org/licenses/lgpl.html
*
* Disclaimer of Warranty.
* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
* EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE
* THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
* SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR
* OR CORRECTION.
*
* Limitation of Liability.
* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER,
* OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO
* YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
* DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
* THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*********************************************************************************************************/
#include "logindialog.h"
#include "ui_logindialog_ui.h"
#include <QWebEngineView>
LoginDialog::LoginDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::LoginDialog)
{
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(i18n("Login"));
connect(m_ui->CancelButton, &QPushButton::clicked, this, &LoginDialog::slotRejected);
connect(m_ui->GetPreview, &QPushButton::clicked, this, &LoginDialog::slotGetPreview);
// m_ui->textBrowser
connect(m_ui->webView, &QWebEngineView::urlChanged, this, &LoginDialog::urlChanged);
connect(m_ui->webView, &QWebEngineView::loadFinished, this, [&](){
this->setCursor(Qt::ArrowCursor);
this->setEnabled(true);
});
}
LoginDialog::~LoginDialog()
{
delete m_ui;
}
void LoginDialog::open()
{
QDialog::open();
setEnabled(false);
setCursor(Qt::WaitCursor);
}
void LoginDialog::slotGetPreview()
{
emit usePreview();
QDialog::accept();
}
void LoginDialog::slotRejected()
{
emit canceled();
QDialog::reject();
}
/**
* @brief LoginDialog::urlChanged
* @param url \n
* If we successfully get a Auth code in our URL we extract the code here and emit LoginDialog::AuthCodeObtained signal
* http://www.freesound.org/docs/api/authentication.html#oauth2-authentication
*/
void LoginDialog::urlChanged(const QUrl &url)
{
const QString str = url.query(QUrl::FullyDecoded);
const int posCode = str.indexOf(QLatin1String("code="));
const int posErr = str.indexOf(QLatin1String("error="));
if (posCode != -1) {
m_strAuthCode = str.mid(posCode + 5);
emit authCodeObtained();
QDialog::accept();
} else if (posErr != -1) {
QString sError = str.mid(posErr + 6);
if (sError == QLatin1String("access_denied")) {
emit accessDenied();
}
QDialog::accept();
}
}
QString LoginDialog::authCode() const
{
return m_strAuthCode;
}
void LoginDialog::setLoginUrl(const QUrl &url)
{
m_ui->webView->setUrl(url);
}
/********************************************************************************************************
* Copyright (C) 2015 Roger Morton (ttguy1@gmail.com)
*
* Purpose: implements client access to freesound.org using ver2 of the freesound API.
*
* Based on code at https://code.google.com/p/qt-oauth-lib/
* Which is Qt Library created by Integrated Computer Solutions, Inc. (ICS)
* to provide OAuth2.0 for the Google API.
*
* Licence: GNU Lesser General Public License
* http://www.gnu.org/licenses/lgpl.html
* This version of the GNU Lesser General Public License incorporates the terms
* and conditions of version 3 of the GNU General Public License http://www.gnu.org/licenses/gpl-3.0-standalone.html
* supplemented by the additional permissions listed at http://www.gnu.org/licenses/lgpl.html
*
* Disclaimer of Warranty.
* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
* EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE
* THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
* SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR
* OR CORRECTION.
*
* Limitation of Liability.
* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER,
* OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO
* YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
* DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
* THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*********************************************************************************************************/
#ifndef LOGINDIALOG_H
#define LOGINDIALOG_H
#include <QDialog>
#include <QString>
#include <QUrl>
namespace Ui {
class LoginDialog;
}
/**
\brief This is the dialog that is used to login to freesound
\details It contains a QWebEngineView object to display the freesound web page. I did try using a QTextBrowser
for this purpose but it responds to the URL that is used to connect with
"No document for
https://www.freesound.org/apiv2/oauth2/authorize/?client_id=3duhagdr874c&redirect_uri=https://www.freesound.org/home/app_permissions/permission_granted/&response_type=code"
*/
class LoginDialog : public QDialog
{
Q_OBJECT
public:
explicit LoginDialog(QWidget *parent = nullptr);
~LoginDialog() override;
void setLoginUrl(const QUrl &url);
QString authCode() const;
signals:
/**
* @brief authCodeObtained - emitted when freesound gives us an Authorisation code \n
* Authorisation codes last 10mins and must be exchanged for an access token in that time
*/
void authCodeObtained();
/**
* @brief accessDenied -signal emitted if freesound denies access - eg bad password or user has denied access to Kdenlive app.
*/
void accessDenied();
/**
* @brief canceled - signal emitted when user clicks cancel button in the logon dialog
*/
void canceled();
/**
* @brief usePreview - signal emitted when user clicks the "use HQ preview" button in the logon dialog
*/
void usePreview();
public slots:
void open() override;
private slots:
void urlChanged(const QUrl &url);
void slotGetPreview();
void slotRejected();
private:
Ui::LoginDialog *m_ui;
QString m_strAuthCode;
};
#endif // LOGINDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LoginDialog</class>
<widget class="QDialog" name="LoginDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>548</width>
<height>456</height>
</rect>
</property>
<property name="windowTitle">
<string>Login Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="FreeSoundLoginLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Login to your account to download the highest quality version of this file. Or use the High Quality preview file instead (no account required).</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QWebEngineView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="GetPreview">
<property name="text">
<string>Get Preview File Instead</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="CancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QWebEngineView</class>
<extends>QWidget</extends>
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
/********************************************************************************************************
* Copyright (C) 2015 Roger Morton (ttguy1@gmail.com)
*
* Purpose: implements client access to freesound.org using ver2 of the freesound API.
*
* Based on code at https://code.google.com/p/qt-oauth-lib/
* Which is Qt Library created by Integrated Computer Solutions, Inc. (ICS)
* to provide OAuth2.0 for the Google API.
*
* Licence: GNU Lesser General Public License
* http://www.gnu.org/licenses/lgpl.html
* This version of the GNU Lesser General Public License incorporates the terms
* and conditions of version 3 of the GNU General Public License http://www.gnu.org/licenses/gpl-3.0-standalone.html
* supplemented by the additional permissions listed at http://www.gnu.org/licenses/lgpl.html
*
* Disclaimer of Warranty.
* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
* EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE
* THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
* SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR
* OR CORRECTION.
*
* Limitation of Liability.
* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER,
* OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO
* YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
* DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF
* THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*********************************************************************************************************/
#include "oauth2.h"
#include "logindialog.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <QJsonParseError>
#include <QUrl>
#include <QUrlQuery>
#include <QDebug>
OAuth2::OAuth2(QWidget *parent)
{
// m_strEndPoint = "https://www.freesound.org/apiv2/oauth2/logout_and_authorize/";
m_strEndPoint = QStringLiteral("https://www.freesound.org/apiv2/oauth2/authorize/");
m_strClientID = QStringLiteral("33e04f36da52710a28cc"); // obtained when ttguy registered the kdenlive application with freesound
m_strRedirectURI = QStringLiteral("https://www.freesound.org/home/app_permissions/permission_granted/");
m_strResponseType = QStringLiteral("code");
m_pParent = parent;
m_bAccessTokenRec = false;
// read a previously saved access token from settings. If the access token is not more that 24hrs old
// it will be valid and will work when OAuth2::obtainAccessToken() is called
// if there is no access token in the settings it will be blank and OAuth2::obtainAccessToken()
// will logon to freesound
// If it is older than 24hrs OAuth2::obtainAccessToken() will fail but then the class will
// request a new access token via a saved refresh_token - that is saved in the kdenlive settings file
// $HOME/.config/kdenlive.rc
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvn
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup authGroup(config, "FreeSoundAuthentication");
QString strAccessTokenFromSettings = authGroup.readEntry(QStringLiteral("freesound_access_token"));
if (!strAccessTokenFromSettings.isEmpty()) {
m_bAccessTokenRec = true;
m_strAccessToken = strAccessTokenFromSettings;
}
buildLoginDialog();
}
void OAuth2::buildLoginDialog()
{
m_pLoginDialog = new LoginDialog(m_pParent);
connect(m_pLoginDialog, &LoginDialog::authCodeObtained, this, &OAuth2::SlotAuthCodeObtained);
connect(m_pLoginDialog, &LoginDialog::accessDenied, this, &OAuth2::SlotAccessDenied);
connect(m_pLoginDialog, &LoginDialog::canceled, this, &OAuth2::SlotCanceled);
connect(m_pLoginDialog, &LoginDialog::usePreview, this, &OAuth2::SlotDownloadPreview);
connect(this, &OAuth2::AuthCodeObtained, this, &OAuth2::SlotAuthCodeObtained);
}
/**
* @brief OAuth2::getClientID - returns QString of the "clientID"
* @return QString of the "clientID" which is a string that identifies the Kdenlive
* application to the freesound website when the request for authentication is made
*/
QString OAuth2::getClientID() const
{
return m_strClientID;
}
/**
* @brief OAuth2::getClientSecret - returns QString of the "client secret"
* @return - QString of the "client secret" which is another string that identifies the Kdenlive
* application to the freesound website when the application asks for an access token
*/
QString OAuth2::getClientSecret() const
{
return OAuth2_strClientSecret;
}
/**
* @brief OAuth2::ForgetAccessToken - clear saved access token from settings and memory /n
* deletes the saved access token from the settings file and from memory.
* Used when the authentication process has failed and has the effect of forcing
* the user to re-authenticate with freesound the next time they try and download a freesound HQ file
*/
void OAuth2::ForgetAccessToken()
{
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup authGroup(config, "FreeSoundAuthentication");
authGroup.deleteEntry(QStringLiteral("freesound_access_token"));
m_bAccessTokenRec = false;
m_strAccessToken.clear();
}
/**
* @brief OAuth2::loginUrl - returns QString containing URL to connect to freesound.
* @return - QString containing URL to connect to freesound. Substitutes clientid,redirecturi and response types into the string
*/
QString OAuth2::loginUrl()
{
QString str = QStringLiteral("%1?client_id=%2&redirect_uri=%3&response_type=%4").arg(m_strEndPoint, m_strClientID, m_strRedirectURI, m_strResponseType);
return str;
}
/**
* @brief OAuth2::obtainAccessToken - Obtains freesound access token. opens the login dialog to connect to freesound if it needs to. \n
* Called by ResourceWidget::slotSaveItem
*
*/
void OAuth2::obtainAccessToken()
{
if (m_bAccessTokenRec) {
emit accessTokenReceived(m_strAccessToken); // if we already have the access token then carry on as if we have already logged on and have the access token
} else {
// login to free sound via our login dialog
QUrl vUrl(loginUrl());
if (!m_pLoginDialog) {
buildLoginDialog();
}
m_pLoginDialog->setLoginUrl(vUrl);
m_pLoginDialog->open();
}
}
/**
* @brief OAuth2::SlotAccessDenied - fires when freesound web site denys access
*/
void OAuth2::SlotAccessDenied()
{
qDebug() << "access denied";
emit accessDenied();
m_pLoginDialog = nullptr;
}
/**
* @brief OAuth2::SlotAuthCodeObtained - fires when the LogonDialog has obtained an Auth Code and has sent the LogonDialog::AuthCodeObtained signal
* This uses the Authorisation Code we have got to request an access token for downloading files
* http://www.freesound.org/docs/api/authentication.html#oauth2-authentication
* When the request finishes OAuth2::serviceRequestFinished will be notified and it will extract the access token and emit accessTokenReceived
*/
void OAuth2::SlotAuthCodeObtained()
{
m_strAuthorizationCode = m_pLoginDialog->authCode(); // get the Auth code we have obtained
m_pLoginDialog = nullptr;
// has a lifetime of 10 minutes
OAuth2::RequestAccessCode(false, m_strAuthorizationCode);
}
/**
* @brief OAuth2::RequestAccessCode - connect to freesound to exchange a authorization code or a refresh token for an access code
* @param pIsReRequest - pass false if you are requesting an access code using a previously obtained authorization code. Pass true if you are requesting a new
* access code via refresh token
* @param pCode - pass an authorisation code here if pIsReRequest is false. Otherwise pass a refresh token here.
*/
void OAuth2::RequestAccessCode(bool pIsReRequest, const QString &pCode)
{
QString vGrantType;
QString vCodeTypeParamName;
// If the access code is older than 24hrs any request to the API using the token will return a 401 (Unauthorized) response showing an ‘Expired token’ error.
// But you can how get a new access token using the refresh token
// curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN"
// "https://www.freesound.org/apiv2/oauth2/access_token/"
if (pIsReRequest) {
vGrantType = QStringLiteral("refresh_token");
vCodeTypeParamName = QStringLiteral("refresh_token");
} else {
vGrantType = QStringLiteral("authorization_code");
vCodeTypeParamName = QStringLiteral("code");
}
auto *networkManager = new QNetworkAccessManager(this);
QUrl serviceUrl = QUrl(QStringLiteral("https://www.freesound.org/apiv2/oauth2/access_token/"));
QUrlQuery postData;
postData.addQueryItem(QStringLiteral("client_id"), this->getClientID());
postData.addQueryItem(QStringLiteral("client_secret"), this->getClientSecret());
postData.addQueryItem(QStringLiteral("grant_type"), vGrantType);
postData.addQueryItem(vCodeTypeParamName, pCode);
connect(networkManager, &QNetworkAccessManager::finished, this, &OAuth2::serviceRequestFinished);
QNetworkRequest request(serviceUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
networkManager->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
}
/**
* @brief OAuth2::serviceRequestFinished - Fires when we finish downloading the access token.
* This is the slot that is notified when OAuth2::SlotAuthCodeObtained has finished downloading the access token.
* It parses the result to extract out the access_token, refresh_token and expires_in values. If it
* extracts the access token successfully if fires the OAuth2::accessTokenReceived signal
* which is picked up by ResourceWidget::slotAccessTokenReceived
* @param reply
* */
void OAuth2::serviceRequestFinished(QNetworkReply *reply)
{
// QString sRefreshToken;
// int iExpiresIn;
QString sErrorText;
if (reply->isFinished()) {
QByteArray sReply = reply->readAll();
QJsonParseError jsonError;
QJsonDocument doc = QJsonDocument::fromJson(sReply, &jsonError);
if (jsonError.error != QJsonParseError::NoError) {
qDebug() << "OAuth2::serviceRequestFinished jsonError.error: " << jsonError.errorString();
ForgetAccessToken();
emit accessTokenReceived(QString()); // notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
} else {
QVariant data = doc.toVariant();
if (data.canConvert(QVariant::Map)) {
QMap<QString, QVariant> map = data.toMap();
if (map.contains(QStringLiteral("access_token"))) {
m_strAccessToken = map.value(QStringLiteral("access_token")).toString();
m_bAccessTokenRec = true;
}
if (map.contains(QStringLiteral("refresh_token"))) {
m_strRefreshToken = map.value(QStringLiteral("refresh_token")).toString();
}
if (map.contains(QStringLiteral("expires_in"))) {
// iExpiresIn = map.value("expires_in").toInt(); //time in seconds until the access_token expires
}
if (map.contains(QStringLiteral("error"))) {
m_bAccessTokenRec = false;
sErrorText = map.value(QStringLiteral("error")).toString();
qDebug() << "OAuth2::serviceRequestFinished map error: " << sErrorText;
ForgetAccessToken();
emit accessTokenReceived(QString()); // notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
}
if (m_bAccessTokenRec) {
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup authGroup(config, "FreeSoundAuthentication");
authGroup.writeEntry(QStringLiteral("freesound_access_token"), m_strAccessToken);
authGroup.writeEntry(QStringLiteral("freesound_refresh_token"), m_strRefreshToken);
// access tokens have a limited lifetime of 24 hours.
emit accessTokenReceived(m_strAccessToken); // notifies ResourceWidget::slotAccessTokenReceived
} else {
ForgetAccessToken();
emit accessTokenReceived(QString()); // notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
}
}
}
}
reply->deleteLater();
}
/**
* @brief OAuth2::SlotCanceled
* Fires when user cancels out of the free sound login dialog - LoginDialog
*/
void OAuth2::SlotCanceled()
{
emit Canceled();
m_pLoginDialog = nullptr;
}
/**
* @brief OAuth2::SlotDownloadPreview
* Fires when user clicks the Use preview file button on the freesound login page LoginDialog.
* emits UsePreview signal that is picked up by ResourceWidget::slotFreesoundUsePreview()
*/
void OAuth2::SlotDownloadPreview()
{