]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LRDD/lib/lrddmethod/webfinger.php
GNU social is with a minor s.
[quix0rs-gnu-social.git] / plugins / LRDD / lib / lrddmethod / webfinger.php
1 <?php
2 /**
3  * Implementation of WebFinger resource discovery (RFC7033)
4  *
5  * @category  Discovery
6  * @package   GNUsocial
7  * @author    Mikael Nordfeldth <mmn@hethane.se>
8  * @copyright 2013 Free Software Foundation, Inc.
9  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
10  * @link      http://status.net/
11  */
12 class LRDDMethod_WebFinger extends LRDDMethod
13 {
14     /**
15      * Simply returns the WebFinger URL over HTTPS at the uri's domain:
16      * https://{domain}/.well-known/webfinger?resource={uri}
17      */
18     public function discover($uri)
19     {
20         if (!Discovery::isAcct($uri)) {
21             throw new Exception('Bad resource URI: '.$uri);
22         }
23         list($user, $domain) = explode('@', parse_url($uri, PHP_URL_PATH));
24         if (!filter_var($domain, FILTER_VALIDATE_IP)
25                 && !filter_var(gethostbyname($domain), FILTER_VALIDATE_IP)) {
26             throw new Exception('Bad resource host.');
27         }
28
29         $link = new XML_XRD_Element_Link(
30                         Discovery::LRDD_REL,
31                         'https://' . $domain . '/.well-known/webfinger?resource={uri}',
32                         Discovery::JRD_MIMETYPE,
33                         true);  //isTemplate
34
35         return array($link);
36     }
37 }