File indexing completed on 2024-04-28 04:55:45

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2017 Andrea Scarpino <scarpino@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "mastodonoauth.h"
0010 
0011 #include <QNetworkReply>
0012 #include <QUrlQuery>
0013 
0014 #include <KIO/AccessManager>
0015 
0016 #include "mastodonaccount.h"
0017 #include "mastodondebug.h"
0018 #include "mastodonoauthreplyhandler.h"
0019 
0020 MastodonOAuth::MastodonOAuth(MastodonAccount *account)
0021     : QOAuth2AuthorizationCodeFlow(account),
0022       m_replyHandler(nullptr), m_networkAccessManager(nullptr)
0023 {
0024     qCDebug(CHOQOK);
0025 
0026     m_replyHandler = new MastodonOAuthReplyHandler(this);
0027     setReplyHandler(m_replyHandler);
0028 
0029     m_networkAccessManager = new KIO::AccessManager(this);
0030     setNetworkAccessManager(m_networkAccessManager);
0031 
0032     setClientIdentifier(account->consumerKey());
0033     setClientIdentifierSharedKey(account->consumerSecret());
0034 
0035     setScope(QLatin1String("read write follow"));
0036 
0037     setAccessTokenUrl(QUrl(account->host() + QLatin1String("/oauth/token")));
0038     setAuthorizationUrl(QUrl(account->host() + QLatin1String("/oauth/authorize")));
0039 }
0040 
0041 MastodonOAuth::~MastodonOAuth()
0042 {
0043     m_replyHandler->deleteLater();
0044     m_networkAccessManager->deleteLater();
0045 }
0046 
0047 void MastodonOAuth::getToken(const QString &code)
0048 {
0049     requestAccessToken(code);
0050 }
0051 
0052 #include "moc_mastodonoauth.cpp"