From af34536a09aea56ccb8fdadd9ffe859f98dec906 Mon Sep 17 00:00:00 2001
From: Kasen IO <kasenvr@gmail.com>
Date: Thu, 30 Jul 2020 00:34:02 -0400
Subject: [PATCH] Further complete the loop.

---
 domain-server/resources/describe-settings.json |  4 ++--
 interface/src/ui/DialogsManager.cpp            | 15 ++++++++++-----
 interface/src/ui/DialogsManager.h              |  2 ++
 interface/src/ui/LoginDialog.cpp               |  4 +---
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json
index f6b6656d7d..281a0be9cc 100644
--- a/domain-server/resources/describe-settings.json
+++ b/domain-server/resources/describe-settings.json
@@ -59,12 +59,12 @@
     },
     {
       "name": "authentication",
-      "label": "Networking / Authentication",
+      "label": "Networking / WordPress OAuth2",
       "settings": [
         {
             "name": "enable_oauth2",
             "label": "Enable OAuth2 Authentication",
-            "help": "Allow a WordPress-based OAuth2 service to assign users to groups based on their role with the service.",
+            "help": "Allow a WordPress-based (miniOrange) OAuth2 service to assign users to groups based on their role with the service.",
             "default": false,
             "type": "checkbox",
             "advanced": true
diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp
index 848663967f..e96b8c5626 100644
--- a/interface/src/ui/DialogsManager.cpp
+++ b/interface/src/ui/DialogsManager.cpp
@@ -29,6 +29,7 @@
 #include "OctreeStatsDialog.h"
 #include "PreferencesDialog.h"
 #include "UpdateDialog.h"
+#include "DomainHandler.h"
 
 #include "scripting/HMDScriptingInterface.h"
 
@@ -130,15 +131,19 @@ void DialogsManager::hideLoginDialog() {
 
 
 void DialogsManager::showDomainLoginDialog() {
+    const QJsonObject& settingsObject = DependencyManager::get<NodeList>()->getDomainHandler().getSettingsObject();
+    static const QString WP_OAUTH2_SERVER_URL = "authentication_oauth2_url_base";
+    
+    if (!settingsObject.contains(WP_OAUTH2_SERVER_URL)) {
+        qDebug() << "Cannot log in to domain because an OAuth2 authorization was required but no authorization server was given.";
+        return;
+    }
+    
+    _domainLoginAuthProvider = settingsObject[WP_OAUTH2_SERVER_URL].toString();
     _isDomainLogin = true;
     LoginDialog::showWithSelection();
 }
 
-// #######: TODO: Domain version of toggleLoginDialog()?
-
-// #######: TODO: Domain version of hiadLoginDialog()?
-
-
 void DialogsManager::showUpdateDialog() {
     UpdateDialog::show();
 }
diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h
index 30127ced68..b76ff69386 100644
--- a/interface/src/ui/DialogsManager.h
+++ b/interface/src/ui/DialogsManager.h
@@ -42,6 +42,7 @@ public:
     void emitAddressBarShown(bool visible) { emit addressBarShown(visible); }
     void setAddressBarVisible(bool addressBarVisible);
     bool getIsDomainLogin() { return _isDomainLogin; }
+    QString getDomainLoginAuthProvider() { return _domainLoginAuthProvider; }
 
 public slots:
     void showAddressBar();
@@ -87,6 +88,7 @@ private:
     bool _addressBarVisible { false };
 
     bool _isDomainLogin { false };
+    QString _domainLoginAuthProvider { "" };
 };
 
 #endif // hifi_DialogsManager_h
diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp
index ac1aa95f19..d64ebdf42a 100644
--- a/interface/src/ui/LoginDialog.cpp
+++ b/interface/src/ui/LoginDialog.cpp
@@ -428,8 +428,6 @@ bool LoginDialog::getDomainLoginRequested() const {
     return DependencyManager::get<DialogsManager>()->getIsDomainLogin();
 }
 
-// ####### TODO: This method may not be necessary.
 QString LoginDialog::getDomainLoginAuthProvider() const {
-    // ####### TODO
-    return QString("https://example.com/oauth2");
+    return DependencyManager::get<DialogsManager>()->getDomainLoginAuthProvider();
 }