From d942054015cc0f3287d7891aeeaf4c091ccf0dc8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 1 May 2014 12:44:42 -0700 Subject: [PATCH] cleanup re-display of OAuthWebView --- domain-server/src/DomainServer.cpp | 4 ++++ interface/src/Application.cpp | 3 +++ interface/src/ui/OAuthWebViewHandler.cpp | 18 ++++++++++++++++-- interface/src/ui/OAuthWebViewHandler.h | 3 +++ libraries/networking/src/NodeList.cpp | 10 +++++++--- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 045436affa..932b45cb6b 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -453,6 +453,10 @@ QUrl DomainServer::oauthAuthorizationURL() { const QString OAUTH_REPSONSE_TYPE_QUERY_VALUE = "code"; authorizationQuery.addQueryItem(OAUTH_RESPONSE_TYPE_QUERY_KEY, OAUTH_REPSONSE_TYPE_QUERY_VALUE); + const QString OAUTH_STATE_QUERY_KEY = "state"; + // create a new UUID that will be the state parameter for oauth authorization AND the new session UUID for that node + authorizationQuery.addQueryItem(OAUTH_STATE_QUERY_KEY, uuidStringWithoutCurlyBraces(QUuid::createUuid())); + QString redirectURL = QString("https://%1:%2/oauth").arg(_hostname).arg(_httpsManager->serverPort()); const QString OAUTH_REDIRECT_URI_QUERY_KEY = "redirect_uri"; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d2ef9c1122..7350a23b9a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3094,6 +3094,9 @@ void Application::domainChanged(const QString& domainHostname) { // reset the voxels renderer _voxels.killLocalVoxels(); + + // reset the auth URL for OAuth web view handler + OAuthWebViewHandler::getInstance().clearLastAuthorizationURL(); } void Application::connectedToDomain(const QString& hostname) { diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index 3ba2a1115a..00202d9a89 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -21,7 +21,9 @@ OAuthWebViewHandler& OAuthWebViewHandler::getInstance() { } OAuthWebViewHandler::OAuthWebViewHandler() : - _activeWebView(NULL) + _activeWebView(NULL), + _webViewRedisplayTimer(), + _lastAuthorizationURL() { } @@ -41,7 +43,19 @@ void OAuthWebViewHandler::addHighFidelityRootCAToSSLConfig() { const int WEB_VIEW_REDISPLAY_ELAPSED_MSECS = 5 * 1000; void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authorizationURL) { - if (!_activeWebView && _webViewRedisplayTimer.elapsed() >= WEB_VIEW_REDISPLAY_ELAPSED_MSECS) { + if (!_activeWebView) { + + if (!_lastAuthorizationURL.isEmpty()) { + if (_lastAuthorizationURL.host() == authorizationURL.host() + && _webViewRedisplayTimer.elapsed() < WEB_VIEW_REDISPLAY_ELAPSED_MSECS) { + // this would be re-displaying an OAuth dialog for the same auth URL inside of the redisplay ms + // so return instead + return; + } + } + + _lastAuthorizationURL = authorizationURL; + _activeWebView = new QWebView; // keep the window on top and delete it when it closes diff --git a/interface/src/ui/OAuthWebViewHandler.h b/interface/src/ui/OAuthWebViewHandler.h index b3a865ce07..3a30705f88 100644 --- a/interface/src/ui/OAuthWebViewHandler.h +++ b/interface/src/ui/OAuthWebViewHandler.h @@ -23,6 +23,8 @@ public: static OAuthWebViewHandler& getInstance(); static void addHighFidelityRootCAToSSLConfig(); + void clearLastAuthorizationURL() { _lastAuthorizationURL = QUrl(); } + public slots: void displayWebviewForAuthorizationURL(const QUrl& authorizationURL); @@ -33,6 +35,7 @@ private slots: private: QPointer _activeWebView; QElapsedTimer _webViewRedisplayTimer; + QUrl _lastAuthorizationURL; }; #endif // hifi_OAuthWebviewHandler_h \ No newline at end of file diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 9714bf11e5..00422f7be9 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -378,12 +378,16 @@ void NodeList::sendDomainServerCheckIn() { } } - PacketType domainPacketType = _sessionUUID.isNull() + PacketType domainPacketType = !_domainHandler.isConnected() ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest; // construct the DS check in packet - QUuid packetUUID = (domainPacketType == PacketTypeDomainListRequest - ? _sessionUUID : _domainHandler.getAssignmentUUID()); + QUuid packetUUID = _sessionUUID; + + if (!_domainHandler.getAssignmentUUID().isNull() && domainPacketType == PacketTypeDomainConnectRequest) { + // for assigned nodes who have not yet connected, send the assignment UUID as this packet UUID + packetUUID = _domainHandler.getAssignmentUUID(); + } QByteArray domainServerPacket = byteArrayWithPopulatedHeader(domainPacketType, packetUUID); QDataStream packetStream(&domainServerPacket, QIODevice::Append);