Once the user completes the flow, update the internal state and report it to observers
| 280 | |
| 281 | // Once the user completes the flow, update the internal state and report it to observers |
| 282 | void DeviceFlow::onVerificationReceived(const QMap<QString, QString> response) { |
| 283 | qDebug() << "DeviceFlow::onVerificationReceived: Emitting closeBrowser()"; |
| 284 | emit closeBrowser(); |
| 285 | |
| 286 | if (response.contains("error")) { |
| 287 | qWarning() << "DeviceFlow::onVerificationReceived: Verification failed:" << response; |
| 288 | updateActivity(Activity::FailedHard); |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | // Check for mandatory tokens |
| 293 | if (response.contains(OAUTH2_ACCESS_TOKEN)) { |
| 294 | qDebug() << "DeviceFlow::onVerificationReceived: Access token returned for implicit or device flow"; |
| 295 | setToken(response.value(OAUTH2_ACCESS_TOKEN)); |
| 296 | if (response.contains(OAUTH2_EXPIRES_IN)) { |
| 297 | bool ok = false; |
| 298 | int expiresIn = response.value(OAUTH2_EXPIRES_IN).toInt(&ok); |
| 299 | if (ok) { |
| 300 | qDebug() << "DeviceFlow::onVerificationReceived: Token expires in" << expiresIn << "seconds"; |
| 301 | setExpires(QDateTime::currentDateTimeUtc().addSecs(expiresIn)); |
| 302 | } |
| 303 | } |
| 304 | if (response.contains(OAUTH2_REFRESH_TOKEN)) { |
| 305 | setRefreshToken(response.value(OAUTH2_REFRESH_TOKEN)); |
| 306 | } |
| 307 | updateActivity(Activity::Succeeded); |
| 308 | } else { |
| 309 | qWarning() << "DeviceFlow::onVerificationReceived: Access token missing from response for implicit or device flow"; |
| 310 | updateActivity(Activity::FailedHard); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // Or if the flow fails or the polling times out, update the internal state with error and report it to observers |
| 315 | void DeviceFlow::serverHasClosed(bool paramsfound) |