From 1bce996181d9ae18756e6bbc0750bb6dc9d09609 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 8 Sep 2014 16:26:48 +0100 Subject: [PATCH] Add /.well-known/webfinger API to lookup user hrefs --- mediagoblin/federation/routing.py | 8 +++- mediagoblin/federation/views.py | 63 ++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/mediagoblin/federation/routing.py b/mediagoblin/federation/routing.py index c1c5a264..e9fa6252 100644 --- a/mediagoblin/federation/routing.py +++ b/mediagoblin/federation/routing.py @@ -72,8 +72,14 @@ add_route( "mediagoblin.federation.views:host_meta" ) +add_route( + "mediagoblin.webfinger.well-known.webfinger", + "/.well-known/webfinger", + "mediagoblin.federation.views:lrdd_lookup" +) + add_route( "mediagoblin.webfinger.whoami", "/api/whoami", "mediagoblin.federation.views:whoami" -) +) \ No newline at end of file diff --git a/mediagoblin/federation/views.py b/mediagoblin/federation/views.py index 350aa36c..724d349c 100644 --- a/mediagoblin/federation/views.py +++ b/mediagoblin/federation/views.py @@ -433,6 +433,14 @@ def host_meta(request): """ links = [ + { + "rel": "lrdd", + "type": "application/json", + "href": request.urlgen( + "mediagoblin.webfinger.well-known.webfinger", + qualified=True + ) + }, { "rel": "registration_endpoint", "href": request.urlgen( @@ -467,7 +475,7 @@ def host_meta(request): "mediagoblin.webfinger.whoami", qualified=True ), - } + }, ] if "application/json" in request.accept_mimetypes: @@ -481,6 +489,59 @@ def host_meta(request): mimetype="application/xrd+xml" ) +def lrdd_lookup(request): + """ + This is the lrdd endpoint which can lookup a user (or + other things such as activities). This is as specified by + RFC6415. + + The cleint must provide a 'resource' as a GET parameter which + should be the query to be looked up. + """ + + if "resource" not in request.args: + return json_error("No resource parameter", status=400) + + resource = request.args["resource"] + + if "@" in resource: + # Lets pull out the username + resource = resource[5:] if resource.startswith("acct:") else resource + username, host = resource.split("@", 1) + + # Now lookup the user + user = User.query.filter_by(username=username).first() + + if user is None: + return json_error( + "Can't find 'user' with username '{0}'".format(username)) + + return json_response([ + { + "rel": "http://webfinger.net/rel/profile-page", + "href": user.url_for_self(request.urlgen), + "type": "text/html" + }, + { + "rel": "self", + "href": request.urlgen( + "mediagoblin.federation.user", + username=user.username, + qualified=True + ) + }, + { + "rel": "activity-outbox", + "href": request.urlgen( + "mediagoblin.federation.feed", + username=user.username, + qualified=True + ) + } + ]) + else: + return json_error("Unrecognized resource parameter", status=404) + def whoami(request): """ /api/whoami - HTTP redirect to API profile """ -- 2.25.1