Debian Codegraph @

src/librssguard/network-web/oauth2service.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/network-web/oauth2service.cpp`/
2
3 ////////////////////////////////////////////////////////////////////////////////
4
5 // //
6 // This file is part of QOAuth2. //
7 // Copyright (c) 2014 Jacob Dawid <[email protected]> //
8 // //
9 // QOAuth2 is free software: you can redistribute it and/or modify //
10 // it under the terms of the GNU Affero General Public License as //
11 // published by the Free Software Foundation, either version 3 of the //
12 // License, or (at your option) any later version. //
13 // //
14 // QOAuth2 is distributed in the hope that it will be useful, //
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
17 // GNU Affero General Public License for more details. //
18 // //
19 // You should have received a copy of the GNU Affero General Public //
20 // License along with QOAuth2. //
21 // If not, see <http://www.gnu.org/licenses/>. //
22 // //
23 ////////////////////////////////////////////////////////////////////////////////
24
25 #include "network-web/oauth2service.h"cxx . . $ `<file>/src/librssguard/network-web/oauth2service.h`/
26
27 #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/
28 #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/
29 #include "network-web/networkfactory.h"cxx . . $ `<file>/src/librssguard/network-web/networkfactory.h`/
30 #include "network-web/oauthhttphandler.h"cxx . . $ `<file>/src/librssguard/network-web/oauthhttphandler.h`/
31 #include "network-web/webfactory.h"cxx . . $ `<file>/src/librssguard/network-web/webfactory.h`/
32
33 #include <cstdlib>
34 #include <utility>
35
36 #include <QDebug>
37 #include <QJsonDocument>
38 #include <QJsonObject>
39 #include <QNetworkReply>
40 #include <QNetworkRequest>
41 #include <QRandomGenerator>
42
43 OAuth2Servicecxx . . $ OAuth2Service#::OAuth2Servicecxx . . $ OAuth2Service#OAuth2Service(1fb840df4dfd8c1).(const QStringcxx . . $ QString#& auth_url,
44 const QStringcxx . . $ QString#& token_url,
45 const QStringcxx . . $ QString#& client_id,
46 const QStringcxx . . $ QString#& client_secret,
47 const QStringcxx . . $ QString#& scope,
48 QObjectcxx . . $ QObject#* parent)
49 : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent), m_idcxx . . $ OAuth2Service#m_id.(QStringcxx . . $ QString#::numbercxx . . $ QString#number(da83c6b4fd8c0e98).(QRandomGeneratorcxx . . $ QRandomGenerator#::globalcxx . . $ QRandomGenerator#global(2e1e8c46584af0f7).()->generatecxx . . $ QRandomGenerator#generate(db52760e79bf9054).())), m_timerIdcxx . . $ OAuth2Service#m_timerId.(-1),
50 m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.(new OAuthHttpHandlercxx . . $ OAuthHttpHandler#(trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("You can close this window now. Go back to %1.").argcxx . . $ QString#arg(ad0bca07273edcc2).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(APP_NAMEcxx . . $ `<built-in>:487:9`!)),
51 this)),
52 m_functorOnLogincxx . . $ OAuth2Service#m_functorOnLogin.(stdcxx . . $ std/function#function(ced63f7c635d850d).::functioncxx . . $ std/function#<void()>()) {
53 m_tokenGrantTypecxx . . $ OAuth2Service#m_tokenGrantType. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("authorization_code");
54 m_tokenUrlcxx . . $ OAuth2Service#m_tokenUrl. =cxx . . $ QUrl#`operator=`(590d023fc9cd4b2d). QUrlcxx . . $ QUrl#QUrl(ea1f3831e370f1cb).(token_url);
55 m_authUrlcxx . . $ OAuth2Service#m_authUrl. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). auth_url;
56
57 m_clientIdcxx . . $ OAuth2Service#m_clientId. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). client_id;
58 m_clientSecretcxx . . $ OAuth2Service#m_clientSecret. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). client_secret;
59 m_clientSecretIdcxx . . $ OAuth2Service#m_clientSecretId. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). m_clientSecretSecretcxx . . $ OAuth2Service#m_clientSecretSecret. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#QString(ced63f7c635d850d).();
60 m_scopecxx . . $ OAuth2Service#m_scope. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). scope;
61 m_useHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#m_useHttpBasicAuthWithClientData. = false;
62
63 connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(&m_networkManagercxx . . $ OAuth2Service#m_networkManager., &QNetworkAccessManagercxx . . $ QNetworkAccessManager#::finishedcxx . . $ QNetworkAccessManager#finished(a14709ced3df193c)., this, &OAuth2Servicecxx . . $ OAuth2Service#::tokenRequestFinishedcxx . . $ OAuth2Service#tokenRequestFinished(a14709ced3df193c).);
64 connectcxx . . $ QObject#connect(93770ac28d6bf547).(m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler., &OAuthHttpHandlercxx . . $ OAuthHttpHandler#::authGrantedcxx . . $ OAuthHttpHandler#authGranted(c1427772cd1877b0)., [this](const QStringcxx . . $ QString#& auth_code, const QStringcxx . . $ QString#& id) {
65 if (id.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() || id ==cxx . . $ `operator==`(5bc2975d2d751687). m_idcxx . . $ OAuth2Service#m_id.) {
66 // We process this further only if handler (static singleton) responded to our original request.
67 retrieveAccessTokencxx . . $ OAuth2Service#retrieveAccessToken(3520e46b33348bf6).(auth_code);
68 }
69 });
70 connectcxx . . $ QObject#connect(93770ac28d6bf547).(m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.,
71 &OAuthHttpHandlercxx . . $ OAuthHttpHandler#::authRejectedcxx . . $ OAuthHttpHandler#authRejected(c1427772cd1877b0).,
72 [this](const QStringcxx . . $ QString#& error_description, const QStringcxx . . $ QString#& id) {
73 Q_UNUSEDcxx . . $ `<external>/17563275351362271547/qtpreprocessorsupport.h:20:9`!(error_description)
74
75 if (id.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() || id ==cxx . . $ `operator==`(5bc2975d2d751687). m_idcxx . . $ OAuth2Service#m_id.) {
76 // We process this further only if handler (static singleton) responded to our original request.
77 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! authFailedcxx . . $ OAuth2Service#authFailed(49f6e7a06ebc5aa8).();
78 }
79 });
80 }
81
82 OAuth2Servicecxx . . $ OAuth2Service#::~cxx . . $ OAuth2Service#`~OAuth2Service`(ced63f7c635d850d).OAuth2Servicecxx . . $ OAuth2Service#() {
83 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Destroying OAuth2Service instance.";
84 }
85
86 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::bearercxx . . $ OAuth2Service#bearer(4365c3963150523e).() {
87 if (!isFullyLoggedIncxx . . $ OAuth2Service#isFullyLoggedIn(50ce9a9e25b4a850).()) {
88 qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::LoginFailurecxx . . $ Notification#Event#LoginFailure.,
89 {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("You have to login first"),
90 trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("Click here to login."),
91 QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Criticalcxx . . $ QSystemTrayIcon#Critical.},
92 {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).},
93 {cxx . . $ GuiAction#GuiAction(7d816f6132cf943f).trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("Login"), [cxx . . $ std/function#function(bdc3712e480e4d04).this]() {
94 logincxx . . $ OAuth2Service#login(c237ffba337c8e2a).();
95 }});
96 return {cxx . . $ QString#QString(ced63f7c635d850d).};
97 }
98 else {
99 return QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("Bearer %1").argcxx . . $ QString#arg(ad0bca07273edcc2).(accessTokencxx . . $ OAuth2Service#accessToken(6ef7b6c27b00b43d).());
100 }
101 }
102
103 bool OAuth2Servicecxx . . $ OAuth2Service#::isFullyLoggedIncxx . . $ OAuth2Service#isFullyLoggedIn(50ce9a9e25b4a850).() const {
104 bool is_expiration_valid = tokensExpireIncxx . . $ OAuth2Service#tokensExpireIn(4e062b5c490497ac).() >cxx . . $ `operator>`(ae3dca24290d889b). QDateTimecxx . . $ QDateTime#::currentDateTimecxx . . $ QDateTime#currentDateTime(bf5129c8228c71c0).();
105 bool do_tokens_exist = !refreshTokencxx . . $ OAuth2Service#refreshToken(6ef7b6c27b00b43d).().isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() && !accessTokencxx . . $ OAuth2Service#accessToken(6ef7b6c27b00b43d).().isEmptycxx . . $ QString#isEmpty(3482b152b9333168).();
106
107 return is_expiration_valid && do_tokens_exist;
108 }
109
110 void OAuth2Servicecxx . . $ OAuth2Service#::setOAuthTokenGrantTypecxx . . $ OAuth2Service#setOAuthTokenGrantType(7df51288a9ebd664).(QStringcxx . . $ QString# grant_type) {
111 m_tokenGrantTypecxx . . $ OAuth2Service#m_tokenGrantType. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(grant_type);
112 }
113
114 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::oAuthTokenGrantTypecxx . . $ OAuth2Service#oAuthTokenGrantType(4365c3963150523e).() {
115 return m_tokenGrantTypecxx . . $ QString#QString(132dd6869045752b).;
116 }
117
118 void OAuth2Servicecxx . . $ OAuth2Service#::timerEventcxx . . $ OAuth2Service#timerEvent(b9e57d1150f23bf5).(QTimerEventcxx . . $ QTimerEvent#* event) {
119 if (m_timerIdcxx . . $ OAuth2Service#m_timerId. >= 0 && event->timerIdcxx . . $ QTimerEvent#timerId(455f465bc33b4cdf).() == m_timerIdcxx . . $ OAuth2Service#m_timerId.) {
120 event->acceptcxx . . $ QEvent#accept(49f6e7a06ebc5aa8).();
121
122 QDateTimecxx . . $ QDateTime# window_about_expire = tokensExpireIncxx . . $ OAuth2Service#tokensExpireIn(4e062b5c490497ac).().addSecscxx . . $ QDateTime#addSecs(95f9ba7c82d0c5e8).(-60 * 15);
123
124 if (window_about_expire <cxx . . $ `operator<`(ae3dca24290d889b). QDateTimecxx . . $ QDateTime#::currentDateTimecxx . . $ QDateTime#currentDateTime(bf5129c8228c71c0).()) {
125 // We try to refresh access token, because it probably expires soon.
126 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Refreshing automatically access token.";
127 refreshAccessTokencxx . . $ OAuth2Service#refreshAccessToken(3520e46b33348bf6).();
128 }
129 else {
130 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Access token is not expired yet.";
131 }
132 }
133
134 QObjectcxx . . $ QObject#::timerEventcxx . . $ QObject#timerEvent(b9e57d1150f23bf5).(event);
135 }
136
137 bool OAuth2Servicecxx . . $ OAuth2Service#::useHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#useHttpBasicAuthWithClientData(50ce9a9e25b4a850).() const {
138 return m_useHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#m_useHttpBasicAuthWithClientData.;
139 }
140
141 void OAuth2Servicecxx . . $ OAuth2Service#::setUseHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#setUseHttpBasicAuthWithClientData(b45ddcbc8423892c).(bool use_auth) {
142 m_useHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#m_useHttpBasicAuthWithClientData. = use_auth;
143 }
144
145 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::clientSecretSecretcxx . . $ OAuth2Service#clientSecretSecret(6ef7b6c27b00b43d).() const {
146 return m_clientSecretSecretcxx . . $ QString#QString(132dd6869045752b).;
147 }
148
149 void OAuth2Servicecxx . . $ OAuth2Service#::setClientSecretSecretcxx . . $ OAuth2Service#setClientSecretSecret(3520e46b33348bf6).(const QStringcxx . . $ QString#& client_secret_secret) {
150 m_clientSecretSecretcxx . . $ OAuth2Service#m_clientSecretSecret. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). client_secret_secret;
151 }
152
153 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::clientSecretIdcxx . . $ OAuth2Service#clientSecretId(6ef7b6c27b00b43d).() const {
154 return m_clientSecretIdcxx . . $ QString#QString(132dd6869045752b).;
155 }
156
157 void OAuth2Servicecxx . . $ OAuth2Service#::setClientSecretIdcxx . . $ OAuth2Service#setClientSecretId(3520e46b33348bf6).(const QStringcxx . . $ QString#& client_secret_id) {
158 m_clientSecretIdcxx . . $ OAuth2Service#m_clientSecretId. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). client_secret_id;
159 }
160
161 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::idcxx . . $ OAuth2Service#id(6ef7b6c27b00b43d).() const {
162 return m_idcxx . . $ QString#QString(132dd6869045752b).;
163 }
164
165 void OAuth2Servicecxx . . $ OAuth2Service#::setIdcxx . . $ OAuth2Service#setId(3520e46b33348bf6).(const QStringcxx . . $ QString#& id) {
166 m_idcxx . . $ OAuth2Service#m_id. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). id;
167 }
168
169 void OAuth2Servicecxx . . $ OAuth2Service#::retrieveAccessTokencxx . . $ OAuth2Service#retrieveAccessToken(3520e46b33348bf6).(const QStringcxx . . $ QString#& auth_code) {
170 QNetworkRequestcxx . . $ QNetworkRequest# network_requestcxx . . $ QNetworkRequest#QNetworkRequest(49f6e7a06ebc5aa8).;
171
172 network_request.setUrlcxx . . $ QNetworkRequest#setUrl(37355d2f77053a23).(m_tokenUrlcxx . . $ OAuth2Service#m_tokenUrl.);
173 network_request.setHeadercxx . . $ QNetworkRequest#setHeader(f2d431fb44b1bb73).(QNetworkRequestcxx . . $ QNetworkRequest#::KnownHeaderscxx . . $ QNetworkRequest#KnownHeaders#::ContentTypeHeadercxx . . $ QNetworkRequest#ContentTypeHeader., "application/x-www-form-urlencoded"cxx . . $ QVariant#QVariant(85c52e162fed56f9).);
174
175 if (m_useHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#m_useHttpBasicAuthWithClientData.) {
176 auto basic_auth = NetworkFactorycxx . . $ NetworkFactory#::generateBasicAuthHeadercxx . . $ NetworkFactory#generateBasicAuthHeader(3d69ae3d4954f7a8).(NetworkFactorycxx . . $ NetworkFactory#::NetworkAuthenticationcxx . . $ NetworkFactory#NetworkAuthentication#::Basiccxx . . $ NetworkFactory#NetworkAuthentication#Basic.,
177 properClientIdcxx . . $ OAuth2Service#properClientId(6ef7b6c27b00b43d).(),
178 properClientSecretcxx . . $ OAuth2Service#properClientSecret(6ef7b6c27b00b43d).());
179
180 network_request.setRawHeadercxx . . $ QNetworkRequest#setRawHeader(a34492a60dbd2bdc).(basic_auth.firstcxx . . $ std/pair#first., basic_auth.secondcxx . . $ std/pair#second.);
181 }
182
183 QStringcxx . . $ QString# content = QStringcxx . . $ QString#QString(85c52e162fed56f9).("client_id=%1&"
184 "client_secret=%2&"
185 "code=%3&"
186 "redirect_uri=%5&"
187 "grant_type=%4")
188 .argcxx . . $ QString#arg(89b093bd48b6d6c0).(properClientIdcxx . . $ OAuth2Service#properClientId(6ef7b6c27b00b43d).(),
189 properClientSecretcxx . . $ OAuth2Service#properClientSecret(6ef7b6c27b00b43d).(),
190 auth_code,
191 m_tokenGrantTypecxx . . $ OAuth2Service#m_tokenGrantType.,
192 m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.->listenAddressPortcxx . . $ HttpServer#listenAddressPort(6ef7b6c27b00b43d).());
193
194 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Posting data for access token retrieval:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(content);
195 m_networkManagercxx . . $ OAuth2Service#m_networkManager..postcxx . . $ QNetworkAccessManager#post(7ed39bc32e459c39).(network_request, content.toUtf8cxx . . $ QString#toUtf8(ef52b713090bc85a).());
196 }
197
198 void OAuth2Servicecxx . . $ OAuth2Service#::refreshAccessTokencxx . . $ OAuth2Service#refreshAccessToken(3520e46b33348bf6).(const QStringcxx . . $ QString#& refresh_token) {
199 auto real_refresh_token = refresh_token.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() ? refreshTokencxx . . $ OAuth2Service#refreshToken(6ef7b6c27b00b43d).() : refresh_tokencxx . . $ QString#QString(132dd6869045752b).;
200 QNetworkRequestcxx . . $ QNetworkRequest# network_requestcxx . . $ QNetworkRequest#QNetworkRequest(49f6e7a06ebc5aa8).;
201
202 network_request.setUrlcxx . . $ QNetworkRequest#setUrl(37355d2f77053a23).(m_tokenUrlcxx . . $ OAuth2Service#m_tokenUrl.);
203 network_request.setHeadercxx . . $ QNetworkRequest#setHeader(f2d431fb44b1bb73).(QNetworkRequestcxx . . $ QNetworkRequest#::KnownHeaderscxx . . $ QNetworkRequest#KnownHeaders#::ContentTypeHeadercxx . . $ QNetworkRequest#ContentTypeHeader., "application/x-www-form-urlencoded"cxx . . $ QVariant#QVariant(85c52e162fed56f9).);
204
205 if (m_useHttpBasicAuthWithClientDatacxx . . $ OAuth2Service#m_useHttpBasicAuthWithClientData.) {
206 auto basic_auth = NetworkFactorycxx . . $ NetworkFactory#::generateBasicAuthHeadercxx . . $ NetworkFactory#generateBasicAuthHeader(3d69ae3d4954f7a8).(NetworkFactorycxx . . $ NetworkFactory#::NetworkAuthenticationcxx . . $ NetworkFactory#NetworkAuthentication#::Basiccxx . . $ NetworkFactory#NetworkAuthentication#Basic.,
207 properClientIdcxx . . $ OAuth2Service#properClientId(6ef7b6c27b00b43d).(),
208 properClientSecretcxx . . $ OAuth2Service#properClientSecret(6ef7b6c27b00b43d).());
209
210 network_request.setRawHeadercxx . . $ QNetworkRequest#setRawHeader(a34492a60dbd2bdc).(basic_auth.firstcxx . . $ std/pair#first., basic_auth.secondcxx . . $ std/pair#second.);
211 }
212
213 QStringcxx . . $ QString# content = QStringcxx . . $ QString#QString(85c52e162fed56f9).("client_id=%1&"
214 "client_secret=%2&"
215 "refresh_token=%3&"
216 "grant_type=%4")
217 .argcxx . . $ QString#arg(89b093bd48b6d6c0).(properClientIdcxx . . $ OAuth2Service#properClientId(6ef7b6c27b00b43d).(), properClientSecretcxx . . $ OAuth2Service#properClientSecret(6ef7b6c27b00b43d).(), real_refresh_token, QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("refresh_token"));
218
219 qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::LoginDataRefreshedcxx . . $ Notification#Event#LoginDataRefreshed.,
220 {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("Logging in via OAuth 2.0..."),
221 trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("Refreshing login tokens for '%1'...").argcxx . . $ QString#arg(ad0bca07273edcc2).(m_tokenUrlcxx . . $ OAuth2Service#m_tokenUrl..toStringcxx . . $ QUrl#toString(632475ebea3355f1).()),
222 QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Informationcxx . . $ QSystemTrayIcon#Information.},
223 {cxx . . $ GuiMessageDestination#GuiMessageDestination(9e113dd3a0d25c95).true, false, true});
224
225 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Posting data for access token refreshing:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(content);
226 m_networkManagercxx . . $ OAuth2Service#m_networkManager..postcxx . . $ QNetworkAccessManager#post(7ed39bc32e459c39).(network_request, content.toUtf8cxx . . $ QString#toUtf8(ef52b713090bc85a).());
227 }
228
229 void OAuth2Servicecxx . . $ OAuth2Service#::tokenRequestFinishedcxx . . $ OAuth2Service#tokenRequestFinished(a14709ced3df193c).(QNetworkReplycxx . . $ QNetworkReply#* network_reply) {
230 QByteArraycxx . . $ QByteArray# repl = network_reply->readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).();
231 QJsonDocumentcxx . . $ QJsonDocument# json_document = QJsonDocumentcxx . . $ QJsonDocument#::fromJsoncxx . . $ QJsonDocument#fromJson(731a4d2b2d08d93c).(repl);
232 QJsonObjectcxx . . $ QJsonObject# root_obj = json_document.objectcxx . . $ QJsonDocument#object(ac8af9874357714b).();
233
234 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Token response:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(QString::fromUtf8(json_document.toJson()));
235
236 if (network_reply->errorcxx . . $ QNetworkReply#error(c916dcceceba1ae7).() != QNetworkReplycxx . . $ QNetworkReply#::NetworkErrorcxx . . $ QNetworkReply#NetworkError#::NoErrorcxx . . $ QNetworkReply#NoError.) {
237 qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`!
238 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Network error when obtaining token response:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(network_reply->error());
239
240 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! tokensRetrieveErrorcxx . . $ OAuth2Service#tokensRetrieveError(3458fe3960d5051).(QStringcxx . . $ QString#QString(ced63f7c635d850d).(), NetworkFactorycxx . . $ NetworkFactory#::networkErrorTextcxx . . $ NetworkFactory#networkErrorText(76e9e349cca0e801).(network_reply->errorcxx . . $ QNetworkReply#error(c916dcceceba1ae7).()));
241 }
242 else if (root_obj.keyscxx . . $ QJsonObject#keys(2b25566bdf736d18).().containscxx . . $ QListSpecialMethods#contains(89bcd3f9aa09e28b).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("error"))) {
243 QStringcxx . . $ QString# error = root_obj.valuecxx . . $ QJsonObject#value(23911ba692ce408c).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("error")).toStringcxx . . $ QJsonValue#toString(6ef7b6c27b00b43d).();
244 QStringcxx . . $ QString# error_description = root_obj.valuecxx . . $ QJsonObject#value(23911ba692ce408c).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("error_description")).toStringcxx . . $ QJsonValue#toString(6ef7b6c27b00b43d).();
245
246 qWarningNNcxx . . $ `src/librssguard/definitions/definitions.h:417:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "JSON error when obtaining token response:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(error)
247 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(error_description);
248
249 logoutcxx . . $ OAuth2Service#logout(b45ddcbc8423892c).();
250
251 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! tokensRetrieveErrorcxx . . $ OAuth2Service#tokensRetrieveError(3458fe3960d5051).(errorcxx . . $ QString#QString(132dd6869045752b)., error_descriptioncxx . . $ QString#QString(132dd6869045752b).);
252 }
253 else {
254 int expires = root_obj.valuecxx . . $ QJsonObject#value(cc3d2a54abecf3c).(QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("expires_in")).toIntcxx . . $ QJsonValue#toInt(7ccb52b1bfe01045).();
255
256 setTokensExpireIncxx . . $ OAuth2Service#setTokensExpireIn(3672ecc950120406).(QDateTimecxx . . $ QDateTime#::currentDateTimecxx . . $ QDateTime#currentDateTime(bf5129c8228c71c0).().addSecscxx . . $ QDateTime#addSecs(95f9ba7c82d0c5e8).(expires));
257 setAccessTokencxx . . $ OAuth2Service#setAccessToken(3520e46b33348bf6).(root_obj.valuecxx . . $ QJsonObject#value(cc3d2a54abecf3c).(QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("access_token")).toStringcxx . . $ QJsonValue#toString(6ef7b6c27b00b43d).());
258
259 const QStringcxx . . $ QString# refresh_token = root_obj.valuecxx . . $ QJsonObject#value(cc3d2a54abecf3c).(QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("refresh_token")).toStringcxx . . $ QJsonValue#toString(6ef7b6c27b00b43d).();
260
261 if (!refresh_token.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) {
262 setRefreshTokencxx . . $ OAuth2Service#setRefreshToken(3520e46b33348bf6).(refresh_token);
263 }
264
265 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Obtained refresh token" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(refreshToken()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "- expires on date/time"
266 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(tokensExpireIn());
267
268 if (m_functorOnLogincxx . . $ OAuth2Service#m_functorOnLogin. !=cxx . . $ std/`operator!=`(4c6f199c20229037). nullptr) {
269 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Running custom after-login code.";
270
271 m_functorOnLogincxx . . $ OAuth2Service#m_functorOnLogin.(cxx . . $ std/function#`operator()`(39e0826ffb540481).);
272 }
273
274 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! tokensRetrievedcxx . . $ OAuth2Service#tokensRetrieved(4d9302a59065db7a).(accessTokencxx . . $ OAuth2Service#accessToken(6ef7b6c27b00b43d).(), refreshTokencxx . . $ OAuth2Service#refreshToken(6ef7b6c27b00b43d).(), expires);
275 }
276
277 network_reply->deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).();
278 }
279
280 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::properClientIdcxx . . $ OAuth2Service#properClientId(6ef7b6c27b00b43d).() const {
281 return m_clientIdcxx . . $ QString#QString(132dd6869045752b)..simplifiedcxx . . $ QString#simplified(dca2c5857e9adf82).().isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() ? m_clientSecretIdcxx . . $ OAuth2Service#m_clientSecretId. : m_clientIdcxx . . $ OAuth2Service#m_clientId.;
282 }
283
284 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::properClientSecretcxx . . $ OAuth2Service#properClientSecret(6ef7b6c27b00b43d).() const {
285 return m_clientSecretcxx . . $ QString#QString(132dd6869045752b)..simplifiedcxx . . $ QString#simplified(dca2c5857e9adf82).().isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() ? m_clientSecretSecretcxx . . $ OAuth2Service#m_clientSecretSecret. : m_clientSecretcxx . . $ OAuth2Service#m_clientSecret.;
286 }
287
288 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::accessTokencxx . . $ OAuth2Service#accessToken(6ef7b6c27b00b43d).() const {
289 return m_accessTokencxx . . $ QString#QString(132dd6869045752b).;
290 }
291
292 void OAuth2Servicecxx . . $ OAuth2Service#::setAccessTokencxx . . $ OAuth2Service#setAccessToken(3520e46b33348bf6).(const QStringcxx . . $ QString#& access_token) {
293 m_accessTokencxx . . $ OAuth2Service#m_accessToken. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). access_token;
294 }
295
296 QDateTimecxx . . $ QDateTime# OAuth2Servicecxx . . $ OAuth2Service#::tokensExpireIncxx . . $ OAuth2Service#tokensExpireIn(4e062b5c490497ac).() const {
297 return m_tokensExpireIncxx . . $ QDateTime#QDateTime(5da15eb5af6b9895).;
298 }
299
300 void OAuth2Servicecxx . . $ OAuth2Service#::setTokensExpireIncxx . . $ OAuth2Service#setTokensExpireIn(3672ecc950120406).(const QDateTimecxx . . $ QDateTime#& tokens_expire_in) {
301 m_tokensExpireIncxx . . $ OAuth2Service#m_tokensExpireIn. =cxx . . $ QDateTime#`operator=`(c9ee2a3e4c661ab0). tokens_expire_in;
302 }
303
304 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::clientSecretcxx . . $ OAuth2Service#clientSecret(6ef7b6c27b00b43d).() const {
305 return m_clientSecretcxx . . $ QString#QString(132dd6869045752b).;
306 }
307
308 void OAuth2Servicecxx . . $ OAuth2Service#::setClientSecretcxx . . $ OAuth2Service#setClientSecret(3520e46b33348bf6).(const QStringcxx . . $ QString#& client_secret) {
309 m_clientSecretcxx . . $ OAuth2Service#m_clientSecret. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). client_secret;
310 }
311
312 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::clientIdcxx . . $ OAuth2Service#clientId(6ef7b6c27b00b43d).() const {
313 return m_clientIdcxx . . $ QString#QString(132dd6869045752b).;
314 }
315
316 void OAuth2Servicecxx . . $ OAuth2Service#::setClientIdcxx . . $ OAuth2Service#setClientId(3520e46b33348bf6).(const QStringcxx . . $ QString#& client_id) {
317 m_clientIdcxx . . $ OAuth2Service#m_clientId. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). client_id;
318 }
319
320 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::redirectUrlcxx . . $ OAuth2Service#redirectUrl(6ef7b6c27b00b43d).() const {
321 return m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.->listenAddressPortcxx . . $ HttpServer#listenAddressPort(6ef7b6c27b00b43d).();
322 }
323
324 void OAuth2Servicecxx . . $ OAuth2Service#::setRedirectUrlcxx . . $ OAuth2Service#setRedirectUrl(37c160c81b6367f7).(const QStringcxx . . $ QString#& redirect_url, bool start_handler) {
325 m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.->setListenAddressPortcxx . . $ HttpServer#setListenAddressPort(37c160c81b6367f7).(redirect_url, start_handler);
326 }
327
328 QStringcxx . . $ QString# OAuth2Servicecxx . . $ OAuth2Service#::refreshTokencxx . . $ OAuth2Service#refreshToken(6ef7b6c27b00b43d).() const {
329 return m_refreshTokencxx . . $ QString#QString(132dd6869045752b).;
330 }
331
332 void OAuth2Servicecxx . . $ OAuth2Service#::setRefreshTokencxx . . $ OAuth2Service#setRefreshToken(3520e46b33348bf6).(const QStringcxx . . $ QString#& refresh_token) {
333 killRefreshTimercxx . . $ OAuth2Service#killRefreshTimer(49f6e7a06ebc5aa8).();
334 m_refreshTokencxx . . $ OAuth2Service#m_refreshToken. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). refresh_token;
335 startRefreshTimercxx . . $ OAuth2Service#startRefreshTimer(49f6e7a06ebc5aa8).();
336 }
337
338 bool OAuth2Servicecxx . . $ OAuth2Service#::logincxx . . $ OAuth2Service#login(c237ffba337c8e2a).(const stdcxx . . $ std/::functioncxx . . $ std/function#<void()>& functor_when_logged_in) {
339 m_functorOnLogincxx . . $ OAuth2Service#m_functorOnLogin. =cxx . . $ std/function#`operator=`(cd4c190db6d6518f). functor_when_logged_in;
340
341 if (!m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.->isListeningcxx . . $ HttpServer#isListening(50ce9a9e25b4a850).()) {
342 qCriticalNNcxx . . $ `src/librssguard/definitions/definitions.h:421:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Cannot log-in because OAuth redirection handler is not listening.";
343
344 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! tokensRetrieveErrorcxx . . $ OAuth2Service#tokensRetrieveError(3458fe3960d5051).(QStringcxx . . $ QString#QString(ced63f7c635d850d).(),
345 trcxx . . $ OAuth2Service#tr(75d9f1c324b4579d).("Failed to start OAuth "
346 "redirection listener. Maybe your "
347 "rights are not high enough."));
348
349 return false;
350 }
351
352 bool did_token_expire = tokensExpireIncxx . . $ OAuth2Service#tokensExpireIn(4e062b5c490497ac).().isNullcxx . . $ QDateTime#isNull(50ce9a9e25b4a850).() || tokensExpireIncxx . . $ OAuth2Service#tokensExpireIn(4e062b5c490497ac).() <cxx . . $ `operator<`(ae3dca24290d889b). QDateTimecxx . . $ QDateTime#::currentDateTimecxx . . $ QDateTime#currentDateTime(bf5129c8228c71c0).().addSecscxx . . $ QDateTime#addSecs(95f9ba7c82d0c5e8).(-120);
353 bool does_token_exist = !refreshTokencxx . . $ OAuth2Service#refreshToken(6ef7b6c27b00b43d).().isEmptycxx . . $ QString#isEmpty(3482b152b9333168).();
354
355 // We refresh current tokens only if:
356 // 1. We have some existing refresh token.
357 // AND
358 // 2. We do not know its expiration date or it passed.
359 if (does_token_exist && did_token_expire) {
360 refreshAccessTokencxx . . $ OAuth2Service#refreshAccessToken(3520e46b33348bf6).();
361 return false;
362 }
363 else if (!does_token_exist) {
364 retrieveAuthCodecxx . . $ OAuth2Service#retrieveAuthCode(49f6e7a06ebc5aa8).();
365 return false;
366 }
367 else {
368 functor_when_logged_in(cxx . . $ std/function#`operator()`(39e0826ffb540481).);
369 return true;
370 }
371 }
372
373 void OAuth2Servicecxx . . $ OAuth2Service#::logoutcxx . . $ OAuth2Service#logout(b45ddcbc8423892c).(bool stop_redirection_handler) {
374 setTokensExpireIncxx . . $ OAuth2Service#setTokensExpireIn(3672ecc950120406).(QDateTimecxx . . $ QDateTime#QDateTime(ced63f7c635d850d).());
375 setAccessTokencxx . . $ OAuth2Service#setAccessToken(3520e46b33348bf6).(QStringcxx . . $ QString#QString(ced63f7c635d850d).());
376 setRefreshTokencxx . . $ OAuth2Service#setRefreshToken(3520e46b33348bf6).(QStringcxx . . $ QString#QString(ced63f7c635d850d).());
377
378 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_OAUTHcxx . . $ `src/librssguard/definitions/definitions.h:186:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Clearing tokens.";
379
380 if (stop_redirection_handler) {
381 m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.->stopcxx . . $ HttpServer#stop(49f6e7a06ebc5aa8).();
382 }
383 }
384
385 void OAuth2Servicecxx . . $ OAuth2Service#::startRefreshTimercxx . . $ OAuth2Service#startRefreshTimer(49f6e7a06ebc5aa8).() {
386 if (!refreshTokencxx . . $ OAuth2Service#refreshToken(6ef7b6c27b00b43d).().isEmptycxx . . $ QString#isEmpty(3482b152b9333168).()) {
387 m_timerIdcxx . . $ OAuth2Service#m_timerId. = startTimercxx . . $ QObject#startTimer(cf5d4a693bb15cf1).(1000 * 60 * 15, Qtcxx . . $ Qt/::TimerTypecxx . . $ Qt/TimerType#::VeryCoarseTimercxx . . $ Qt/VeryCoarseTimer.);
388 }
389 }
390
391 void OAuth2Servicecxx . . $ OAuth2Service#::killRefreshTimercxx . . $ OAuth2Service#killRefreshTimer(49f6e7a06ebc5aa8).() {
392 if (m_timerIdcxx . . $ OAuth2Service#m_timerId. > 0) {
393 killTimercxx . . $ QObject#killTimer(d4f767463ce0a6b3).(m_timerIdcxx . . $ OAuth2Service#m_timerId.);
394 }
395 }
396
397 void OAuth2Servicecxx . . $ OAuth2Service#::retrieveAuthCodecxx . . $ OAuth2Service#retrieveAuthCode(49f6e7a06ebc5aa8).() {
398 QStringcxx . . $ QString# auth_url = m_authUrlcxx . . $ OAuth2Service#m_authUrl. + QStringcxx . . $ QString#QString(85c52e162fed56f9).("?client_id=%1&"
399 "scope=%2&"
400 "redirect_uri=%3&"
401 "response_type=code&"
402 "state=%4&"
403 "prompt=consent&"
404 "duration=permanent&"
405 "access_type=offline")
406 .argcxx . . $ QString#arg(89b093bd48b6d6c0).(properClientIdcxx . . $ OAuth2Service#properClientId(6ef7b6c27b00b43d).(), m_scopecxx . . $ OAuth2Service#m_scope., m_redirectionHandlercxx . . $ OAuth2Service#m_redirectionHandler.->listenAddressPortcxx . . $ HttpServer#listenAddressPort(6ef7b6c27b00b43d).(), m_idcxx . . $ OAuth2Service#m_id.);
407
408 // We run login URL in external browser, response is caught by light HTTP server.
409 qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->webcxx . . $ Application#web(ad68e16c93841931).()->openUrlInExternalBrowsercxx . . $ WebFactory#openUrlInExternalBrowser(dd54f9efb9153ea5).(auth_urlcxx . . $ QUrl#QUrl(ea1f3831e370f1cb).);
410 }