diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index 6ef7bebdce..3ba2a1115a 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -38,8 +38,10 @@ void OAuthWebViewHandler::addHighFidelityRootCAToSSLConfig() { QSslConfiguration::setDefaultConfiguration(sslConfig); } +const int WEB_VIEW_REDISPLAY_ELAPSED_MSECS = 5 * 1000; + void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authorizationURL) { - if (!_activeWebView) { + if (!_activeWebView && _webViewRedisplayTimer.elapsed() >= WEB_VIEW_REDISPLAY_ELAPSED_MSECS) { _activeWebView = new QWebView; // keep the window on top and delete it when it closes @@ -52,9 +54,24 @@ void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authoriz connect(_activeWebView->page()->networkAccessManager(), &QNetworkAccessManager::sslErrors, this, &OAuthWebViewHandler::handleSSLErrors); + connect(_activeWebView, &QWebView::loadFinished, this, &OAuthWebViewHandler::handleLoadFinished); + + // connect to the destroyed signal so after the web view closes we can start a timer + connect(_activeWebView, &QWebView::destroyed, this, &OAuthWebViewHandler::handleWebViewDestroyed); } } void OAuthWebViewHandler::handleSSLErrors(QNetworkReply* networkReply, const QList& errorList) { qDebug() << "SSL Errors:" << errorList; } + +void OAuthWebViewHandler::handleLoadFinished(bool success) { + if (success && _activeWebView->url().host() == NodeList::getInstance()->getDomainHandler().getHostname()) { + qDebug() << "OAuth authorization code passed successfully to domain-server."; + _activeWebView->close(); + } +} + +void OAuthWebViewHandler::handleWebViewDestroyed(QObject* destroyedObject) { + _webViewRedisplayTimer.restart(); +} diff --git a/interface/src/ui/OAuthWebViewHandler.h b/interface/src/ui/OAuthWebViewHandler.h index 692a31dc75..b3a865ce07 100644 --- a/interface/src/ui/OAuthWebViewHandler.h +++ b/interface/src/ui/OAuthWebViewHandler.h @@ -28,8 +28,11 @@ public slots: private slots: void handleSSLErrors(QNetworkReply* networkReply, const QList& errorList); + void handleLoadFinished(bool success); + void handleWebViewDestroyed(QObject* destroyedObject); private: QPointer _activeWebView; + QElapsedTimer _webViewRedisplayTimer; }; #endif // hifi_OAuthWebviewHandler_h \ No newline at end of file