diff options
-rw-r--r-- | mediagoblin/routing.py | 4 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/webfinger/host-meta.xml | 27 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/webfinger/xrd.xml | 27 | ||||
-rw-r--r-- | mediagoblin/webfinger/__init__.py | 25 | ||||
-rw-r--r-- | mediagoblin/webfinger/routing.py | 25 | ||||
-rw-r--r-- | mediagoblin/webfinger/views.py | 117 |
6 files changed, 225 insertions, 0 deletions
diff --git a/mediagoblin/routing.py b/mediagoblin/routing.py index ae56f8cb..bd727db5 100644 --- a/mediagoblin/routing.py +++ b/mediagoblin/routing.py @@ -21,6 +21,8 @@ from mediagoblin.submit.routing import submit_routes from mediagoblin.user_pages.routing import user_routes from mediagoblin.edit.routing import edit_routes from mediagoblin.listings.routing import tag_routes +from mediagoblin.webfinger.routing import webfinger_well_known_routes, \ + webfinger_routes def get_mapper(): @@ -36,5 +38,7 @@ def get_mapper(): mapping.extend(user_routes, '/u') mapping.extend(edit_routes, '/edit') mapping.extend(tag_routes, '/tag') + mapping.extend(webfinger_well_known_routes, '/.well-known') + mapping.extend(webfinger_routes, '/api/webfinger') return mapping diff --git a/mediagoblin/templates/mediagoblin/webfinger/host-meta.xml b/mediagoblin/templates/mediagoblin/webfinger/host-meta.xml new file mode 100644 index 00000000..95a1a176 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/webfinger/host-meta.xml @@ -0,0 +1,27 @@ +{# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# 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/>. +-#} +<?xml version="1.0" encoding="UTF-8"?> +<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" + xmlns:hm="http://host-meta.net/xrd/1.0"> + + <hm:Host>{{ request.host }}</hm:Host> + + <Link rel="lrdd" + template="{{ lrdd_template|replace(placeholder, '{uri}') }}"> + <Title>{{ lrdd_title }}</Title> + </Link> +</XRD> diff --git a/mediagoblin/templates/mediagoblin/webfinger/xrd.xml b/mediagoblin/templates/mediagoblin/webfinger/xrd.xml new file mode 100644 index 00000000..1fe34577 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/webfinger/xrd.xml @@ -0,0 +1,27 @@ +{# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# 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/>. +-#} +<?xml version="1.0" encoding="UTF-8"?> +<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"> + + <Subject>{{ subject }}</Subject> + <Alias>{{ alias }}</Alias> + {% for link in links %} + <Link + {%- for attr, value in link.attrs.items() %} {{ attr }}="{{ value}}" + {%- endfor %} /> + {%- endfor %} +</XRD> diff --git a/mediagoblin/webfinger/__init__.py b/mediagoblin/webfinger/__init__.py new file mode 100644 index 00000000..ec7ec884 --- /dev/null +++ b/mediagoblin/webfinger/__init__.py @@ -0,0 +1,25 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# 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/>. +''' +mediagoblin.webfinger_ provides an LRDD discovery service and +a web host meta information file + +Links: +- `LRDD Discovery Draft + <http://tools.ietf.org/html/draft-hammer-discovery-06>`_. +- `RFC 6415 - Web Host Metadata + <http://tools.ietf.org/html/rfc6415>`_. +''' diff --git a/mediagoblin/webfinger/routing.py b/mediagoblin/webfinger/routing.py new file mode 100644 index 00000000..effb2bf2 --- /dev/null +++ b/mediagoblin/webfinger/routing.py @@ -0,0 +1,25 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# 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/>. + +from routes.route import Route + +webfinger_well_known_routes = [ + Route('mediagoblin.webfinger.host_meta', '/host-meta', + controller='mediagoblin.webfinger.views:host_meta')] + +webfinger_routes = [ + Route('mediagoblin.webfinger.xrd', '/xrd', + controller='mediagoblin.webfinger.views:xrd')] diff --git a/mediagoblin/webfinger/views.py b/mediagoblin/webfinger/views.py new file mode 100644 index 00000000..22086396 --- /dev/null +++ b/mediagoblin/webfinger/views.py @@ -0,0 +1,117 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# 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/>. +''' +For references, see docstring in mediagoblin/webfinger/__init__.py +''' + +import re + +from urlparse import urlparse + +from mediagoblin.tools.response import render_to_response, render_404 + +def host_meta(request): + ''' + Webfinger host-meta + ''' + + placeholder = 'MG_LRDD_PLACEHOLDER' + + lrdd_title = 'GNU MediaGoblin - User lookup' + + lrdd_template = request.urlgen( + 'mediagoblin.webfinger.xrd', + uri=placeholder, + qualified=True) + + return render_to_response( + request, + 'mediagoblin/webfinger/host-meta.xml', + {'request': request, + 'lrdd_template': lrdd_template, + 'lrdd_title': lrdd_title, + 'placeholder': placeholder}) + +MATCH_SCHEME_PATTERN = re.compile(r'^acct:') + +def xrd(request): + ''' + Find user data based on a webfinger URI + ''' + param_uri = request.GET.get('uri') + + if not param_uri: + return render_404(request) + + ''' + :py:module:`urlparse` does not recognize usernames in URIs of the + form ``acct:user@example.org`` or ``user@example.org``. + ''' + if not MATCH_SCHEME_PATTERN.search(param_uri): + # Assume the URI is in the form ``user@example.org`` + uri = 'acct://' + param_uri + else: + # Assumes the URI looks like ``acct:user@example.org + uri = MATCH_SCHEME_PATTERN.sub( + 'acct://', param_uri) + + parsed = urlparse(uri) + + xrd_subject = param_uri + + # TODO: Verify that the user exists + # Q: Does webfinger support error handling in this case? + # Returning 404 seems intuitive, need to check. + if parsed.username: + # The user object + # TODO: Fetch from database instead of using the MockUser + user = MockUser() + user.username = parsed.username + + xrd_links = [ + {'attrs': { + 'rel': 'http://microformats.org/profile/hcard', + 'href': request.urlgen( + 'mediagoblin.user_pages.user_home', + user=user.username, + qualified=True)}}, + {'attrs': { + 'rel': 'http://schemas.google.com/g/2010#updates-from', + 'href': request.urlgen( + 'mediagoblin.user_pages.atom_feed', + user=user.username, + qualified=True)}}] + + xrd_alias = request.urlgen( + 'mediagoblin.user_pages.user_home', + user=user.username, + qualified=True) + + return render_to_response( + request, + 'mediagoblin/webfinger/xrd.xml', + {'request': request, + 'subject': xrd_subject, + 'alias': xrd_alias, + 'links': xrd_links }) + else: + return render_404(request) + +class MockUser(object): + ''' + TEMPORARY user object + ''' + username = None |