forked from GNUsocial/gnu-social
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
New plugins: * LRDD LRDD implements client-side RFC6415 and RFC7033 resource descriptor discovery procedures. I.e. LRDD, host-meta and WebFinger stuff. OStatus and OpenID now depend on the LRDD plugin (XML_XRD). * WebFinger This plugin implements the server-side of RFC6415 and RFC7033. Note: WebFinger technically doesn't handle XRD, but we serve both that and JRD (JSON Resource Descriptor), depending on Accept header and one ugly hack to check for old StatusNet installations. WebFinger depends on LRDD. We might make this even prettier by using Net_WebFinger, but it is not currently RFC7033 compliant (no /.well-known/webfinger resource GETs). Disabling the WebFinger plugin would effectively render your site non- federated (which might be desired on a private site). Disabling the LRDD plugin would make your site unable to do modern web URI lookups (making life just a little bit harder).
This commit is contained in:
202
plugins/LRDD/lib/discovery.php
Normal file
202
plugins/LRDD/lib/discovery.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2010, StatusNet, Inc.
|
||||
*
|
||||
* This class performs lookups based on methods implemented in separate
|
||||
* classes, where a resource uri is given. Examples are WebFinger (RFC7033)
|
||||
* and the LRDD (Link-based Resource Descriptor Discovery) in RFC6415.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package GNUSocial
|
||||
* @author James Walker <james@status.net>
|
||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @copyright 2013 Free Software Foundation, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://www.gnu.org/software/social/
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
class Discovery
|
||||
{
|
||||
const LRDD_REL = 'lrdd';
|
||||
const UPDATESFROM = 'http://schemas.google.com/g/2010#updates-from';
|
||||
const HCARD = 'http://microformats.org/profile/hcard';
|
||||
|
||||
const JRD_MIMETYPE_OLD = 'application/json'; // RFC6415 uses this
|
||||
const JRD_MIMETYPE = 'application/jrd+json';
|
||||
const XRD_MIMETYPE = 'application/xrd+xml';
|
||||
|
||||
public $methods = array();
|
||||
|
||||
/**
|
||||
* Constructor for a discovery object
|
||||
*
|
||||
* Registers different discovery methods.
|
||||
*
|
||||
* @return Discovery this
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (Event::handle('StartDiscoveryMethodRegistration', array($this))) {
|
||||
Event::handle('EndDiscoveryMethodRegistration', array($this));
|
||||
}
|
||||
}
|
||||
|
||||
public static function supportedMimeTypes()
|
||||
{
|
||||
return array('json'=>self::JRD_MIMETYPE,
|
||||
'jsonold'=>self::JRD_MIMETYPE_OLD,
|
||||
'xml'=>self::XRD_MIMETYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a discovery class
|
||||
*
|
||||
* @param string $class Class name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerMethod($class)
|
||||
{
|
||||
$this->methods[] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a user ID, return the first available resource descriptor
|
||||
*
|
||||
* @param string $id User ID URI
|
||||
*
|
||||
* @return XML_XRD object for the resource descriptor of the id
|
||||
*/
|
||||
public function lookup($id)
|
||||
{
|
||||
// Normalize the incoming $id to make sure we have a uri
|
||||
$uri = self::normalize($id);
|
||||
|
||||
foreach ($this->methods as $class) {
|
||||
try {
|
||||
$xrd = new XML_XRD();
|
||||
|
||||
common_debug("LRDD discovery method for '$uri': {$class}");
|
||||
$lrdd = new $class;
|
||||
$links = call_user_func(array($lrdd, 'discover'), $uri);
|
||||
$link = Discovery::getService($links, Discovery::LRDD_REL);
|
||||
|
||||
// Load the LRDD XRD
|
||||
if (!empty($link->template)) {
|
||||
$xrd_uri = Discovery::applyTemplate($link->template, $uri);
|
||||
} elseif (!empty($link->href)) {
|
||||
$xrd_uri = $link->href;
|
||||
} else {
|
||||
throw new Exception('No resource descriptor URI in link.');
|
||||
}
|
||||
|
||||
$client = new HTTPClient();
|
||||
$headers = array();
|
||||
if (!is_null($link->type)) {
|
||||
$headers[] = "Accept: {$link->type}";
|
||||
}
|
||||
|
||||
$response = $client->get($xrd_uri, $headers);
|
||||
if ($response->getStatus() != 200) {
|
||||
throw new Exception('Unexpected HTTP status code.');
|
||||
}
|
||||
|
||||
$xrd->loadString($response->getBody());
|
||||
return $xrd;
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// TRANS: Exception. %s is an ID.
|
||||
throw new Exception(sprintf(_('Unable to find services for %s.'), $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of links, returns the matching service
|
||||
*
|
||||
* @param array $links Links to check (as instances of XML_XRD_Element_Link)
|
||||
* @param string $service Service to find
|
||||
*
|
||||
* @return array $link assoc array representing the link
|
||||
*/
|
||||
public static function getService(array $links, $service)
|
||||
{
|
||||
foreach ($links as $link) {
|
||||
if ($link->rel === $service) {
|
||||
return $link;
|
||||
}
|
||||
common_debug('LINK: rel '.$link->rel.' !== '.$service);
|
||||
}
|
||||
|
||||
throw new Exception('No service link found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a "user id" make sure it's normalized to an acct: uri
|
||||
*
|
||||
* @param string $user_id User ID to normalize
|
||||
*
|
||||
* @return string normalized acct: URI
|
||||
*/
|
||||
public static function normalize($uri)
|
||||
{
|
||||
if (is_null($uri) || $uri==='') {
|
||||
throw new Exception(_('No resource given.'));
|
||||
}
|
||||
|
||||
$parts = parse_url($uri);
|
||||
// If we don't have a scheme, but the path implies user@host,
|
||||
// though this is far from a perfect matching procedure...
|
||||
if (!isset($parts['scheme']) && isset($parts['path'])
|
||||
&& preg_match('/[\w@\w]/u', $parts['path'])) {
|
||||
return 'acct:' . $uri;
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function isAcct($uri)
|
||||
{
|
||||
return (mb_strtolower(mb_substr($uri, 0, 5)) == 'acct:');
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a template using an ID
|
||||
*
|
||||
* Replaces {uri} in template string with the ID given.
|
||||
*
|
||||
* @param string $template Template to match
|
||||
* @param string $uri URI to replace with
|
||||
*
|
||||
* @return string replaced values
|
||||
*/
|
||||
public static function applyTemplate($template, $uri)
|
||||
{
|
||||
$template = str_replace('{uri}', urlencode($uri), $template);
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
|
129
plugins/LRDD/lib/linkheader.php
Normal file
129
plugins/LRDD/lib/linkheader.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2010, StatusNet, Inc.
|
||||
*
|
||||
* Parse HTTP response for interesting Link: headers
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package StatusNet
|
||||
* @author James Walker <james@status.net>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to represent Link: headers in an HTTP response
|
||||
*
|
||||
* Since these are a fairly important part of Hammer-stack discovery, they're
|
||||
* reified and implemented here.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package StatusNet
|
||||
* @author James Walker <james@status.net>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*
|
||||
* @see Discovery
|
||||
*/
|
||||
class LinkHeader
|
||||
{
|
||||
var $href;
|
||||
var $rel;
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Initialize from a string
|
||||
*
|
||||
* @param string $str Link: header value
|
||||
*
|
||||
* @return LinkHeader self
|
||||
*/
|
||||
function __construct($str)
|
||||
{
|
||||
preg_match('/^<[^>]+>/', $str, $uri_reference);
|
||||
//if (empty($uri_reference)) return;
|
||||
|
||||
$this->href = trim($uri_reference[0], '<>');
|
||||
$this->rel = array();
|
||||
$this->type = null;
|
||||
|
||||
// remove uri-reference from header
|
||||
$str = substr($str, strlen($uri_reference[0]));
|
||||
|
||||
// parse link-params
|
||||
$params = explode(';', $str);
|
||||
|
||||
foreach ($params as $param) {
|
||||
if (empty($param)) {
|
||||
continue;
|
||||
}
|
||||
list($param_name, $param_value) = explode('=', $param, 2);
|
||||
|
||||
$param_name = trim($param_name);
|
||||
$param_value = preg_replace('(^"|"$)', '', trim($param_value));
|
||||
|
||||
// for now we only care about 'rel' and 'type' link params
|
||||
// TODO do something with the other links-params
|
||||
switch ($param_name) {
|
||||
case 'rel':
|
||||
$this->rel = trim($param_value);
|
||||
break;
|
||||
|
||||
case 'type':
|
||||
$this->type = trim($param_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an HTTP response, return the requested Link: header
|
||||
*
|
||||
* @param HTTP_Request2_Response $response response to check
|
||||
* @param string $rel relationship to look for
|
||||
* @param string $type media type to look for
|
||||
*
|
||||
* @return LinkHeader discovered header, or null on failure
|
||||
*/
|
||||
static function getLink($response, $rel=null, $type=null)
|
||||
{
|
||||
$headers = $response->getHeader('Link');
|
||||
if ($headers) {
|
||||
// Can get an array or string, so try to simplify the path
|
||||
if (!is_array($headers)) {
|
||||
$headers = array($headers);
|
||||
}
|
||||
|
||||
foreach ($headers as $header) {
|
||||
$lh = new LinkHeader($header);
|
||||
|
||||
if ((is_null($rel) || $lh->rel == $rel) &&
|
||||
(is_null($type) || $lh->type == $type)) {
|
||||
return $lh->href;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
55
plugins/LRDD/lib/lrddmethod.php
Normal file
55
plugins/LRDD/lib/lrddmethod.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Abstract class for LRDD discovery methods
|
||||
*
|
||||
* Objects that extend this class can retrieve an array of
|
||||
* resource descriptor links for the URI. The array consists
|
||||
* of XML_XRD_Element_Link elements.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package StatusNet
|
||||
* @author James Walker <james@status.net>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
abstract class LRDDMethod
|
||||
{
|
||||
protected $xrd = null;
|
||||
|
||||
public function __construct() {
|
||||
$this->xrd = new XML_XRD();
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover interesting info about the URI
|
||||
*
|
||||
* @param string $uri URI to inquire about
|
||||
*
|
||||
* @return array of XML_XRD_Element_Link elements to discovered resource descriptors
|
||||
*/
|
||||
abstract public function discover($uri);
|
||||
|
||||
protected function fetchUrl($url, $method=HTTPClient::METHOD_GET)
|
||||
{
|
||||
$client = new HTTPClient();
|
||||
|
||||
// GAAHHH, this method sucks! How about we make a better HTTPClient interface?
|
||||
switch ($method) {
|
||||
case HTTPClient::METHOD_GET:
|
||||
$response = $client->get($url);
|
||||
break;
|
||||
case HTTPClient::METHOD_HEAD:
|
||||
$response = $client->head($url);
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Bad HTTP method.');
|
||||
}
|
||||
|
||||
if ($response->getStatus() != 200) {
|
||||
throw new Exception('Unexpected HTTP status code.');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
60
plugins/LRDD/lib/lrddmethod/hostmeta.php
Normal file
60
plugins/LRDD/lib/lrddmethod/hostmeta.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Implementation of discovery using host-meta file
|
||||
*
|
||||
* Discovers resource descriptor file for a user by going to the
|
||||
* organization's host-meta file and trying to find a template for LRDD.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package StatusNet
|
||||
* @author James Walker <james@status.net>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
class LRDDMethod_HostMeta extends LRDDMethod
|
||||
{
|
||||
/**
|
||||
* 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.');
|
||||
}
|
||||
}
|
50
plugins/LRDD/lib/lrddmethod/linkheader.php
Normal file
50
plugins/LRDD/lib/lrddmethod/linkheader.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Implementation of discovery using HTTP Link header
|
||||
*
|
||||
* Discovers XRD file for a user by fetching the URL and reading any
|
||||
* Link: headers in the HTTP response.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package StatusNet
|
||||
* @author James Walker <james@status.net>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
class LRDDMethod_LinkHeader extends LRDDMethod
|
||||
{
|
||||
/**
|
||||
* For HTTP IDs fetch the URL and look for Link headers.
|
||||
*
|
||||
* @todo fail out of WebFinger URIs faster
|
||||
*/
|
||||
public function discover($uri)
|
||||
{
|
||||
$response = self::fetchUrl($uri, HTTPClient::METHOD_HEAD);
|
||||
|
||||
$link_header = $response->getHeader('Link');
|
||||
if (empty($link_header)) {
|
||||
throw new Exception('No Link header found');
|
||||
}
|
||||
common_debug('LRDD LinkHeader found: '.var_export($link_header,true));
|
||||
|
||||
return self::parseHeader($link_header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string or array of headers, returns JRD-like assoc array
|
||||
*
|
||||
* @param string|array $header string or array of strings for headers
|
||||
*
|
||||
* @return array of associative arrays in JRD-like array format
|
||||
*/
|
||||
protected static function parseHeader($header)
|
||||
{
|
||||
$lh = new LinkHeader($header);
|
||||
|
||||
$link = new XML_XRD_Element_Link($lh->rel, $lh->href, $lh->type);
|
||||
|
||||
return array($link);
|
||||
}
|
||||
}
|
79
plugins/LRDD/lib/lrddmethod/linkhtml.php
Normal file
79
plugins/LRDD/lib/lrddmethod/linkhtml.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Implementation of discovery using HTML <link> element
|
||||
*
|
||||
* Discovers XRD file for a user by fetching the URL and reading any
|
||||
* <link> elements in the HTML response.
|
||||
*
|
||||
* @category Discovery
|
||||
* @package StatusNet
|
||||
* @author James Walker <james@status.net>
|
||||
* @copyright 2010 StatusNet, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
class LRDDMethod_LinkHTML extends LRDDMethod
|
||||
{
|
||||
/**
|
||||
* For HTTP IDs, fetch the URL and look for <link> elements
|
||||
* in the HTML response.
|
||||
*
|
||||
* @todo fail out of WebFinger URIs faster
|
||||
*/
|
||||
public function discover($uri)
|
||||
{
|
||||
$response = self::fetchUrl($uri);
|
||||
|
||||
return self::parse($response->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse HTML and return <link> elements
|
||||
*
|
||||
* Given an HTML string, scans the string for <link> elements
|
||||
*
|
||||
* @param string $html HTML to scan
|
||||
*
|
||||
* @return array array of associative arrays in JRD-ish array format
|
||||
*/
|
||||
public function parse($html)
|
||||
{
|
||||
$links = array();
|
||||
|
||||
preg_match('/<head(\s[^>]*)?>(.*?)<\/head>/is', $html, $head_matches);
|
||||
$head_html = $head_matches[2];
|
||||
|
||||
preg_match_all('/<link\s[^>]*>/i', $head_html, $link_matches);
|
||||
|
||||
foreach ($link_matches[0] as $link_html) {
|
||||
$link_url = null;
|
||||
$link_rel = null;
|
||||
$link_type = null;
|
||||
|
||||
preg_match('/\srel=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $rel_matches);
|
||||
if ( isset($rel_matches[3]) ) {
|
||||
$link_rel = $rel_matches[3];
|
||||
} else if ( isset($rel_matches[1]) ) {
|
||||
$link_rel = $rel_matches[1];
|
||||
}
|
||||
|
||||
preg_match('/\shref=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $href_matches);
|
||||
if ( isset($href_matches[3]) ) {
|
||||
$link_uri = $href_matches[3];
|
||||
} else if ( isset($href_matches[1]) ) {
|
||||
$link_uri = $href_matches[1];
|
||||
}
|
||||
|
||||
preg_match('/\stype=(("|\')([^\\2]*?)\\2|[^"\'\s]+)/i', $link_html, $type_matches);
|
||||
if ( isset($type_matches[3]) ) {
|
||||
$link_type = $type_matches[3];
|
||||
} else if ( isset($type_matches[1]) ) {
|
||||
$link_type = $type_matches[1];
|
||||
}
|
||||
|
||||
$links[] = new XML_XRD_Element_Link($link_rel, $link_uri, $link_type);
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
37
plugins/LRDD/lib/lrddmethod/webfinger.php
Normal file
37
plugins/LRDD/lib/lrddmethod/webfinger.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Implementation of WebFinger resource discovery (RFC7033)
|
||||
*
|
||||
* @category Discovery
|
||||
* @package GNUSocial
|
||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||
* @copyright 2013 Free Software Foundation, Inc.
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
||||
* @link http://status.net/
|
||||
*/
|
||||
class LRDDMethod_WebFinger 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user