From b7537e7b06b5f2b772cb971ac8637a98e359135b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 19 Apr 2018 19:17:15 -0600 Subject: [PATCH] Add Webfinger utility --- app/Util/Webfinger/Webfinger.php | 122 ++++++++++++++++++++++++++++ app/Util/Webfinger/WebfingerUrl.php | 19 +++++ 2 files changed, 141 insertions(+) create mode 100644 app/Util/Webfinger/Webfinger.php create mode 100644 app/Util/Webfinger/WebfingerUrl.php diff --git a/app/Util/Webfinger/Webfinger.php b/app/Util/Webfinger/Webfinger.php new file mode 100644 index 000000000..4de7010e4 --- /dev/null +++ b/app/Util/Webfinger/Webfinger.php @@ -0,0 +1,122 @@ +user = $user; + $this->subject = ''; + $this->aliases = array(); + $this->links = array(); + } + + public function setSubject() + { + $host = parse_url(config('app.url'), PHP_URL_HOST); + $username = $this->user->username; + + $this->subject = 'acct:'.$username.'@'.$host; + return $this; + } + + public function generateAliases() + { + $host = parse_url(config('app.url'), PHP_URL_HOST); + $username = $this->user->username; + $url = $this->user->url(); + + $this->aliases = [ + 'acct:'.$username.'@'.$host, + $url + ]; + return $this; + } + + public function generateLinks() + { + $user = $this->user; + + $this->links = [ + [ + 'rel' => 'http://webfinger.net/rel/profile-page', + 'type' => 'text/html', + 'href' => $user->url() + ], + [ + 'rel' => 'http://gmpg.org/xfn/11', + 'type' => 'text/html', + 'href' => $user->url() + ], + [ + 'rel' => 'describedby', + 'type' => 'application\/rdf+xml', + 'href' => $user->url('/foaf') + ], + [ + 'rel' => 'http://apinamespace.org/atom', + 'type' => 'application/atomsvc+xml', + 'href' => url('/api/statusnet/app/service/admin.xml') + ], + [ + 'rel' => 'http://apinamespace.org/twitter', + 'href' => url('/api/') + ], + [ + 'rel' => 'http://specs.openid.net/auth/2.0/provider', + 'href' => $user->url() + ], + [ + 'rel' => 'http://schemas.google.com/g/2010#updates-from', + 'type' => 'application/atom+xml', + 'href' => url("/api/statuses/user_timeline/{$user->id}.atom") + ], + [ + 'rel' => 'magic-public-key', + 'href' => '' + ], + [ + 'rel' => 'salmon', + 'href' => $user->url('/salmon') + ], + [ + 'rel' => 'http://salmon-protocol.org/ns/salmon-replies', + 'href' => $user->url('/salmon') + ], + [ + 'rel' => 'http://salmon-protocol.org/ns/salmon-mention', + 'href' => $user->url('/salmon') + ], + [ + 'rel' => 'http://ostatus.org/schema/1.0/subscribe', + 'href' => url('/main/ostatussub?profile={uri}') + ] + ]; + return $this; + } + + public function generate() + { + $this->setSubject(); + $this->generateAliases(); + $this->generateLinks(); + + return [ + 'subject' => $this->subject, + 'aliases' => $this->aliases, + 'links' => $this->links + ]; + } + + + +} \ No newline at end of file diff --git a/app/Util/Webfinger/WebfingerUrl.php b/app/Util/Webfinger/WebfingerUrl.php new file mode 100644 index 000000000..2eb21c3b8 --- /dev/null +++ b/app/Util/Webfinger/WebfingerUrl.php @@ -0,0 +1,19 @@ +