. namespace Component\FreeNetwork\Util\LrddMethod; use Component\FreeNetwork\Util\Discovery; use Component\FreeNetwork\Util\LrddMethod; use Exception; use XML_XRD_Element_Link; /** * Implementation of WebFinger resource discovery (RFC7033) * * @category Discovery * @package GNUsocial * * @author Mikael Nordfeldth * @copyright 2013 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class LrddMethodWebfinger extends LRDDMethod { /** * Simply returns the WebFinger URL over HTTPS at the uri's domain: * https://{domain}/.well-known/webfinger?resource={uri} */ public function discover($uri) { $parts = explode('@', parse_url($uri, \PHP_URL_PATH), 2); if (!Discovery::isAcct($uri) || \count($parts) != 2) { throw new Exception('Bad resource URI: ' . $uri); } [, $domain] = $parts; 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 [$link]; } }