MCPcopy Create free account
hub / github.com/MultiMC/Launcher / onDeviceAuthReplyFinished

Method onDeviceAuthReplyFinished

libraries/katabasis/src/DeviceFlow.cpp:180–235  ·  view source on GitHub ↗

Then, once we get them, present them to the user

Source from the content-addressed store, hash-verified

178
179// Then, once we get them, present them to the user
180void DeviceFlow::onDeviceAuthReplyFinished()
181{
182 qDebug() << "DeviceFlow::onDeviceAuthReplyFinished";
183 QNetworkReply *tokenReply = qobject_cast<QNetworkReply *>(sender());
184 if (!tokenReply)
185 {
186 qDebug() << "DeviceFlow::onDeviceAuthReplyFinished: reply is null";
187 return;
188 }
189 if (tokenReply->error() == QNetworkReply::NoError) {
190 QByteArray replyData = tokenReply->readAll();
191
192 // Dump replyData
193 // SENSITIVE DATA in RelWithDebInfo or Debug builds
194 //qDebug() << "DeviceFlow::onDeviceAuthReplyFinished: replyData\n";
195 //qDebug() << QString( replyData );
196
197 QVariantMap params = parseJsonResponse(replyData);
198
199 // Dump tokens
200 qDebug() << "DeviceFlow::onDeviceAuthReplyFinished: Tokens returned:\n";
201 foreach (QString key, params.keys()) {
202 // SENSITIVE DATA in RelWithDebInfo or Debug builds, so it is truncated first
203 qDebug() << key << ": "<< params.value( key ).toString();
204 }
205
206 // Check for mandatory parameters
207 if (hasMandatoryDeviceAuthParams(params)) {
208 qDebug() << "DeviceFlow::onDeviceAuthReplyFinished: Device auth request response";
209
210 const QString userCode = params.take(OAUTH2_USER_CODE).toString();
211 QUrl uri = params.take(OAUTH2_VERIFICATION_URI).toUrl();
212 if (uri.isEmpty())
213 uri = params.take(OAUTH2_VERIFICATION_URL).toUrl();
214
215 if (params.contains(OAUTH2_VERIFICATION_URI_COMPLETE))
216 emit openBrowser(params.take(OAUTH2_VERIFICATION_URI_COMPLETE).toUrl());
217
218 bool ok = false;
219 int expiresIn = params[OAUTH2_EXPIRES_IN].toInt(&ok);
220 if (!ok) {
221 qWarning() << "DeviceFlow::startPollServer: No expired_in parameter";
222 updateActivity(Activity::FailedHard);
223 return;
224 }
225
226 emit showVerificationUriAndCode(uri, userCode, expiresIn);
227
228 startPollServer(params, expiresIn);
229 } else {
230 qWarning() << "DeviceFlow::onDeviceAuthReplyFinished: Mandatory parameters missing from response";
231 updateActivity(Activity::FailedHard);
232 }
233 }
234 tokenReply->deleteLater();
235}
236
237// Spin up polling for the user completing the login flow out of band

Callers

nothing calls this directly

Calls 6

parseJsonResponseFunction · 0.85
errorMethod · 0.80
isEmptyMethod · 0.80
toStringMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected