likes work!
[shpub.git] / src / shpub / Command / Connect.php
index 2e7e266ffe810ca7dba4f93f1ce54fbd2b5bb91b..bd1606eb849c96f6d64b99d616ac37c4907d41a2 100644 (file)
@@ -17,9 +17,13 @@ class Command_Connect
     public function run($server, $user, $newKey, $force)
     {
         $host = $this->getHost($newKey != '' ? $newKey : $server, $force);
+        if ($host === null) {
+            //already taken
+            return;
+        }
         if ($host->endpoints->incomplete()) {
             $host->server = $server;
-            $this->discoverEndpoints($server, $host->endpoints);
+            $host->loadEndpoints();
         }
 
         list($redirect_uri, $socketStr) = $this->getHttpServerData();
@@ -116,50 +120,9 @@ class Command_Connect
                 return;
             }
         }
-        if ($host->endpoints === null) {
-            $host->endpoints = new Config_Endpoints();
-        }
         return $host;
     }
 
-    function discoverEndpoints($url, $cfg)
-    {
-        //TODO: discovery via link headers
-        $sx = simplexml_load_file($url);
-        if ($sx === false) {
-            Log::err('Error loading URL: ' . $url);
-            exit(1);
-        }
-        $sx->registerXPathNamespace('h', 'http://www.w3.org/1999/xhtml');
-
-        $auths = $sx->xpath(
-            '/h:html/h:head/h:link[@rel="authorization_endpoint" and @href]'
-        );
-        if (!count($auths)) {
-            Log::err('No authorization endpoint found');
-            exit(1);
-        }
-        $cfg->authorization = (string) $auths[0]['href'];
-
-        $tokens = $sx->xpath(
-            '/h:html/h:head/h:link[@rel="token_endpoint" and @href]'
-        );
-        if (!count($tokens)) {
-            Log::err('No token endpoint found');
-            exit(1);
-        }
-        $cfg->token = (string) $tokens[0]['href'];
-
-        $mps = $sx->xpath(
-            '/h:html/h:head/h:link[@rel="micropub" and @href]'
-        );
-        if (!count($mps)) {
-            Log::err('No micropub endpoint found');
-            exit(1);
-        }
-        $cfg->micropub = (string) $mps[0]['href'];
-    }
-
     protected function getHttpServerData()
     {
         //FIXME: get IP from SSH_CONNECTION