From: xray7224 <jessica@megworld.co.uk> Date: Tue, 3 Sep 2013 16:17:07 +0000 (+0100) Subject: Support some webfinger API's and real profile and /api/user/<user>/ X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a5682e89602ddc266d05c760a319d7647755f0b4;p=mediagoblin.git Support some webfinger API's and real profile and /api/user/<user>/ --- diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4377f60f..4f5182d6 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -148,7 +148,7 @@ class User(Base, UserMixin): "links": { "self": { "href": request.urlgen( - "mediagoblin.federation.profile", + "mediagoblin.federation.user.profile", username=self.username, qualified=True ), diff --git a/mediagoblin/federation/routing.py b/mediagoblin/federation/routing.py index 16184866..daf60d00 100644 --- a/mediagoblin/federation/routing.py +++ b/mediagoblin/federation/routing.py @@ -24,9 +24,9 @@ add_route( ) add_route( - "mediagoblin.federation.profile", + "mediagoblin.federation.user.profile", "/api/user/<string:username>/profile", - "mediagoblin.federation.views:user" + "mediagoblin.federation.views:profile" ) # Inbox and Outbox (feed) @@ -53,3 +53,15 @@ add_route( "/api/<string:objectType>/<string:uuid>/comments", "mediagoblin.federation.views:object_comments" ) + +add_route( + "mediagoblin.webfinger.well-known.host-meta", + "/.well-known/host-meta", + "mediagoblin.federation.views:host_meta" + ) + +add_route( + "mediagoblin.webfinger.whoami", + "/api/whoami", + "mediagoblin.federation.views:whoami" + ) diff --git a/mediagoblin/federation/views.py b/mediagoblin/federation/views.py index ab67e457..85bf1540 100644 --- a/mediagoblin/federation/views.py +++ b/mediagoblin/federation/views.py @@ -1,10 +1,10 @@ from mediagoblin.decorators import oauth_required from mediagoblin.db.models import User, MediaEntry -from mediagoblin.tools.response import json_response +from mediagoblin.tools.response import redirect, json_response -@oauth_required -def user(request): - """ Handles user response at /api/user/<username>/ """ +#@oauth_required +def profile(request, raw=False): + """ This is /api/user/<username>/profile - This will give profile info """ user = request.matchdict["username"] requested_user = User.query.filter_by(username=user) @@ -15,9 +15,24 @@ def user(request): user = requested_user[0] + if raw: + return (user, user.serialize(request)) + # user profiles are public so return information return json_response(user.serialize(request)) +def user(request): + """ This is /api/user/<username> - This will get the user """ + user, user_profile = profile(request, raw=True) + data = { + "nickname": user.username, + "updated": user.created.isoformat(), + "published": user.created.isoformat(), + "profile": user_profile + } + + return json_response(data) + @oauth_required def feed(request): """ Handles the user's outbox - /api/user/<username>/feed """ @@ -78,3 +93,41 @@ def object_comments(request): response = json_response(comments) return response + + +## +# Well known +## +def host_meta(request): + """ This is /.well-known/host-meta - provides URL's to resources on server """ + links = [] + + # Client registration links + links.append({ + "ref": "registration_endpoint", + "href": request.urlgen("mediagoblin.oauth.client_register", qualified=True), + }) + links.append({ + "ref": "http://apinamespace.org/oauth/request_token", + "href": request.urlgen("mediagoblin.oauth.request_token", qualified=True), + }) + links.append({ + "ref": "http://apinamespace.org/oauth/authorize", + "href": request.urlgen("mediagoblin.oauth.authorize", qualified=True), + }) + links.append({ + "ref": "http://apinamespace.org/oauth/access_token", + "href": request.urlgen("mediagoblin.oauth.access_token", qualified=True), + }) + + return json_response(links) + +def whoami(request): + """ This is /api/whoami - This is a HTTP redirect to api profile """ + profile = request.urlgen( + "mediagoblin.federation.user.profile", + username=request.user.username, + qualified=True + ) + + return redirect(request, location=profile) diff --git a/mediagoblin/oauth/routing.py b/mediagoblin/oauth/routing.py index e45077bb..7f2aa11d 100644 --- a/mediagoblin/oauth/routing.py +++ b/mediagoblin/oauth/routing.py @@ -18,25 +18,25 @@ from mediagoblin.tools.routing import add_route # client registration & oauth add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.client_register", "/api/client/register", "mediagoblin.oauth.views:client_register" ) add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.request_token", "/oauth/request_token", "mediagoblin.oauth.views:request_token" ) add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.authorize", "/oauth/authorize", "mediagoblin.oauth.views:authorize", ) add_route( - "mediagoblin.oauth", + "mediagoblin.oauth.access_token", "/oauth/access_token", "mediagoblin.oauth.views:access_token" )