3 * Implementation of discovery using host-meta file
5 * Discovers resource descriptor file for a user by going to the
6 * organization's host-meta file and trying to find a template for LRDD.
10 * @author James Walker <james@status.net>
11 * @copyright 2010 StatusNet, Inc.
12 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
13 * @link http://status.net/
15 class LRDDMethod_HostMeta extends LRDDMethod
18 * For RFC6415 and HTTP URIs, fetch the host-meta file
19 * and look for LRDD templates
21 public function discover($uri)
23 // This is allowed for RFC6415 but not the 'WebFinger' RFC7033.
24 $try_schemes = array('https', 'http');
26 $scheme = mb_strtolower(parse_url($uri, PHP_URL_SCHEME));
29 if (!Discovery::isAcct($uri)) {
30 throw new Exception('Bad resource URI: '.$uri);
32 // We can't use parse_url data for this, since the 'host'
33 // entry is only set if the scheme has '://' after it.
34 list($user, $domain) = explode('@', parse_url($uri, PHP_URL_PATH));
38 $domain = mb_strtolower(parse_url($uri, PHP_URL_HOST));
39 $try_schemes = array($scheme);
42 throw new Exception('Unable to discover resource descriptor endpoint.');
45 foreach ($try_schemes as $scheme) {
46 $url = $scheme . '://' . $domain . '/.well-known/host-meta';
49 $response = self::fetchUrl($url);
50 $this->xrd->loadString($response->getBody());
51 } catch (Exception $e) {
52 common_debug('LRDD could not load resource descriptor: '.$url.' ('.$e->getMessage().')');
55 return $this->xrd->links;
58 throw new Exception('Unable to retrieve resource descriptor links.');