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