webfinger.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. $link = new XML_XRD_Element_Link(
  29. Discovery::LRDD_REL,
  30. 'https://' . $domain . '/.well-known/webfinger?resource={uri}',
  31. Discovery::JRD_MIMETYPE,
  32. true); //isTemplate
  33. return array($link);
  34. }
  35. }