Add XRD+XML formatting for /.well-known/host-meta
This commit is contained in:
parent
f251d99828
commit
0af1b85998
@ -23,7 +23,8 @@ from werkzeug.datastructures import FileStorage
|
|||||||
from mediagoblin.decorators import oauth_required
|
from mediagoblin.decorators import oauth_required
|
||||||
from mediagoblin.federation.decorators import user_has_privilege
|
from mediagoblin.federation.decorators import user_has_privilege
|
||||||
from mediagoblin.db.models import User, MediaEntry, MediaComment
|
from mediagoblin.db.models import User, MediaEntry, MediaComment
|
||||||
from mediagoblin.tools.response import redirect, json_response, json_error
|
from mediagoblin.tools.response import redirect, json_response, json_error, \
|
||||||
|
render_to_response
|
||||||
from mediagoblin.meddleware.csrf import csrf_exempt
|
from mediagoblin.meddleware.csrf import csrf_exempt
|
||||||
from mediagoblin.submit.lib import new_upload_entry, api_upload_request, \
|
from mediagoblin.submit.lib import new_upload_entry, api_upload_request, \
|
||||||
api_add_to_feed
|
api_add_to_feed
|
||||||
@ -418,42 +419,68 @@ def object_comments(request):
|
|||||||
return json_response(comments)
|
return json_response(comments)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Well known
|
# RFC6415 - Web Host Metadata
|
||||||
##
|
##
|
||||||
def host_meta(request):
|
def host_meta(request):
|
||||||
""" /.well-known/host-meta - provide URLs to resources """
|
"""
|
||||||
links = []
|
This provides the host-meta URL information that is outlined
|
||||||
|
in RFC6415. By default this should provide XRD+XML however
|
||||||
|
if the client accepts JSON we will provide that over XRD+XML.
|
||||||
|
The 'Accept' header is used to decude this.
|
||||||
|
|
||||||
links.append({
|
A client should use this endpoint to determine what URLs to
|
||||||
"ref": "registration_endpoint",
|
use for OAuth endpoints.
|
||||||
"href": request.urlgen(
|
"""
|
||||||
"mediagoblin.oauth.client_register",
|
|
||||||
qualified=True
|
links = [
|
||||||
),
|
{
|
||||||
})
|
"rel": "registration_endpoint",
|
||||||
links.append({
|
"href": request.urlgen(
|
||||||
"ref": "http://apinamespace.org/oauth/request_token",
|
"mediagoblin.oauth.client_register",
|
||||||
"href": request.urlgen(
|
qualified=True
|
||||||
"mediagoblin.oauth.request_token",
|
),
|
||||||
qualified=True
|
},
|
||||||
),
|
{
|
||||||
})
|
"rel": "http://apinamespace.org/oauth/request_token",
|
||||||
links.append({
|
"href": request.urlgen(
|
||||||
"ref": "http://apinamespace.org/oauth/authorize",
|
"mediagoblin.oauth.request_token",
|
||||||
"href": request.urlgen(
|
qualified=True
|
||||||
"mediagoblin.oauth.authorize",
|
),
|
||||||
qualified=True
|
},
|
||||||
),
|
{
|
||||||
})
|
"rel": "http://apinamespace.org/oauth/authorize",
|
||||||
links.append({
|
"href": request.urlgen(
|
||||||
"ref": "http://apinamespace.org/oauth/access_token",
|
"mediagoblin.oauth.authorize",
|
||||||
"href": request.urlgen(
|
qualified=True
|
||||||
"mediagoblin.oauth.access_token",
|
),
|
||||||
qualified=True
|
},
|
||||||
),
|
{
|
||||||
})
|
"rel": "http://apinamespace.org/oauth/access_token",
|
||||||
|
"href": request.urlgen(
|
||||||
|
"mediagoblin.oauth.access_token",
|
||||||
|
qualified=True
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rel": "http://apinamespace.org/activitypub/whoami",
|
||||||
|
"href": request.urlgen(
|
||||||
|
"mediagoblin.webfinger.whoami",
|
||||||
|
qualified=True
|
||||||
|
),
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
if "application/json" in request.accept_mimetypes:
|
||||||
|
return json_response({"links": links})
|
||||||
|
|
||||||
|
# provide XML+XRD
|
||||||
|
return render_to_response(
|
||||||
|
request,
|
||||||
|
"mediagoblin/federation/host-meta.xml",
|
||||||
|
{"links": links},
|
||||||
|
mimetype="application/xrd+xml"
|
||||||
|
)
|
||||||
|
|
||||||
return json_response({"links": links})
|
|
||||||
|
|
||||||
def whoami(request):
|
def whoami(request):
|
||||||
""" /api/whoami - HTTP redirect to API profile """
|
""" /api/whoami - HTTP redirect to API profile """
|
||||||
|
22
mediagoblin/templates/mediagoblin/federation/host-meta.xml
Normal file
22
mediagoblin/templates/mediagoblin/federation/host-meta.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{# GNU MediaGoblin -- federated, autonomous media hosting
|
||||||
|
# Copyright (C) 2014 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'>
|
||||||
|
{% for link in links %}
|
||||||
|
<Link rel="{{ link.rel }}" href="{{ link.href }}" />
|
||||||
|
{% endfor %}
|
||||||
|
</XRD>
|
@ -29,11 +29,12 @@ class Response(wz_Response):
|
|||||||
default_mimetype = u'text/html'
|
default_mimetype = u'text/html'
|
||||||
|
|
||||||
|
|
||||||
def render_to_response(request, template, context, status=200):
|
def render_to_response(request, template, context, status=200, mimetype=None):
|
||||||
"""Much like Django's shortcut.render()"""
|
"""Much like Django's shortcut.render()"""
|
||||||
return Response(
|
return Response(
|
||||||
render_template(request, template, context),
|
render_template(request, template, context),
|
||||||
status=status)
|
status=status,
|
||||||
|
mimetype=mimetype)
|
||||||
|
|
||||||
def render_error(request, status=500, title=_('Oops!'),
|
def render_error(request, status=500, title=_('Oops!'),
|
||||||
err_msg=_('An error occured')):
|
err_msg=_('An error occured')):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user