Merge remote branch 'remotes/joar/webfinger'

* remotes/joar/webfinger:
  Added references to docstring in mediagoblin.webfinger
  Removed mediagoblin.tools.feed which was accidentally included
  Polishing the webfinger implementation
  webfinger fully compliant with webfinger.org! Still *preliminary* solution.
  Changed some thngs to be compatible with webfinger.org, still *very preliminary*
  Added *very preliminary* support for webfinger
This commit is contained in:
Elrond 2011-12-20 22:58:16 +01:00
commit 463a5dcc43
6 changed files with 225 additions and 0 deletions

View File

@ -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

View File

@ -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>

View File

@ -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>

View File

@ -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>`_.
'''

View File

@ -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')]

View File

@ -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