Ejemplo n.º 1
0
 /**
  * For RFC6415 and HTTP URIs, fetch the host-meta file
  * and look for LRDD templates
  */
 public function discover($uri)
 {
     // This is allowed for RFC6415 but not the 'WebFinger' RFC7033.
     $try_schemes = array('https', 'http');
     $scheme = mb_strtolower(parse_url($uri, PHP_URL_SCHEME));
     switch ($scheme) {
         case 'acct':
             if (!Discovery::isAcct($uri)) {
                 throw new Exception('Bad resource URI: ' . $uri);
             }
             // We can't use parse_url data for this, since the 'host'
             // entry is only set if the scheme has '://' after it.
             list($user, $domain) = explode('@', parse_url($uri, PHP_URL_PATH));
             break;
         case 'http':
         case 'https':
             $domain = mb_strtolower(parse_url($uri, PHP_URL_HOST));
             $try_schemes = array($scheme);
             break;
         default:
             throw new Exception('Unable to discover resource descriptor endpoint.');
     }
     foreach ($try_schemes as $scheme) {
         $url = $scheme . '://' . $domain . '/.well-known/host-meta';
         try {
             $response = self::fetchUrl($url);
             $this->xrd->loadString($response->getBody());
         } catch (Exception $e) {
             common_debug('LRDD could not load resource descriptor: ' . $url . ' (' . $e->getMessage() . ')');
             continue;
         }
         return $this->xrd->links;
     }
     throw new Exception('Unable to retrieve resource descriptor links.');
 }
Ejemplo n.º 2
0
 /**
  * Simply returns the WebFinger URL over HTTPS at the uri's domain:
  * https://{domain}/.well-known/webfinger?resource={uri}
  */
 public function discover($uri)
 {
     if (!Discovery::isAcct($uri)) {
         throw new Exception('Bad resource URI: ' . $uri);
     }
     list($user, $domain) = explode('@', parse_url($uri, PHP_URL_PATH));
     if (!filter_var($domain, FILTER_VALIDATE_IP) && !filter_var(gethostbyname($domain), FILTER_VALIDATE_IP)) {
         throw new Exception('Bad resource host.');
     }
     $link = new XML_XRD_Element_Link(Discovery::LRDD_REL, 'https://' . $domain . '/.well-known/webfinger?resource={uri}', Discovery::JRD_MIMETYPE, true);
     //isTemplate
     return array($link);
 }
Ejemplo n.º 3
0
 public function onEndGetWebFingerResource($resource, WebFingerResource &$target = null, array $args = array())
 {
     $profile = null;
     if (Discovery::isAcct($resource)) {
         $parts = explode('@', substr(urldecode($resource), 5));
         // 5 is strlen of 'acct:'
         if (count($parts) == 2) {
             list($nick, $domain) = $parts;
             if ($domain === common_config('site', 'server')) {
                 $nick = common_canonical_nickname($nick);
                 $user = User::getKV('nickname', $nick);
                 if (!$user instanceof User) {
                     throw new NoSuchUserException(array('nickname' => $nick));
                 }
                 $profile = $user->getProfile();
             } else {
                 throw new Exception(_('Remote profiles not supported via WebFinger yet.'));
             }
         }
     } else {
         $user = User::getKV('uri', $resource);
         if ($user instanceof User) {
             $profile = $user->getProfile();
         } else {
             // try and get it by profile url
             $profile = Profile::getKV('profileurl', $resource);
         }
     }
     if ($profile instanceof Profile) {
         $target = new WebFingerResource_Profile($profile);
         return false;
         // We got our target, stop handler execution
     }
     $notice = Notice::getKV('uri', $resource);
     if ($notice instanceof Notice) {
         $target = new WebFingerResource_Notice($notice);
         return false;
     }
     return true;
 }