Spin up polling for the user completing the login flow out of band
| 245 | |
| 246 | // Spin up polling for the user completing the login flow out of band |
| 247 | void DeviceFlow::startPollServer(const QVariantMap ¶ms, int expiresIn) |
| 248 | { |
| 249 | qDebug() << "DeviceFlow::startPollServer: device_ and user_code expires in" << expiresIn << "seconds"; |
| 250 | |
| 251 | QUrl url(options_.accessTokenUrl); |
| 252 | QNetworkRequest authRequest(url); |
| 253 | authRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); |
| 254 | |
| 255 | const QString deviceCode = params[OAUTH2_DEVICE_CODE].toString(); |
| 256 | const QString grantType = grantType_.isEmpty() ? OAUTH2_GRANT_TYPE_DEVICE : grantType_; |
| 257 | |
| 258 | QList<RequestParameter> parameters; |
| 259 | parameters.append(RequestParameter(OAUTH2_CLIENT_ID, options_.clientIdentifier.toUtf8())); |
| 260 | if ( !options_.clientSecret.isEmpty() ) { |
| 261 | parameters.append(RequestParameter(OAUTH2_CLIENT_SECRET, options_.clientSecret.toUtf8())); |
| 262 | } |
| 263 | parameters.append(RequestParameter(OAUTH2_CODE, deviceCode.toUtf8())); |
| 264 | parameters.append(RequestParameter(OAUTH2_GRANT_TYPE, grantType.toUtf8())); |
| 265 | QByteArray payload = createQueryParameters(parameters); |
| 266 | |
| 267 | PollServer * pollServer = new PollServer(manager_, authRequest, payload, expiresIn, this); |
| 268 | if (params.contains(OAUTH2_INTERVAL)) { |
| 269 | bool ok = false; |
| 270 | int interval = params[OAUTH2_INTERVAL].toInt(&ok); |
| 271 | if (ok) { |
| 272 | pollServer->setInterval(interval); |
| 273 | } |
| 274 | } |
| 275 | connect(pollServer, &PollServer::verificationReceived, this, &DeviceFlow::onVerificationReceived); |
| 276 | connect(pollServer, &PollServer::serverClosed, this, &DeviceFlow::serverHasClosed); |
| 277 | setPollServer(pollServer); |
| 278 | pollServer->startPolling(); |
| 279 | } |
| 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) { |
nothing calls this directly
no test coverage detected