Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

in progress, halfway done

  • Loading branch information...
commit 433f47da188b2049e8dba624fc494275ce8d9ddb 1 parent f65fd9e
Ryan Barrett authored
View
9 README
@@ -0,0 +1,9 @@
+This is a stand-in, proxy webfinger server for sites that don't implement
+webfinger themselves. It's deployed at http://webfinger-unofficial.appspot.com/
+and currently supports Facebook and Twitter.
+
+Feel free to add implementations for more sites!
+
+Background on webfinger:
+http://code.google.com/p/webfinger/wiki/WebFingerProtocol
+http://hueniverse.com/2009/09/implementing-webfinger/
View
85 app.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+"""Renders and serves the /.well-known/host-meta and /user?uri=... URLs.
+"""
+
+__author__ = 'Ryan Barrett <webfinger-unofficial@ryanb.org>'
+
+import appengine_config
+
+import logging
+import os
+import urlparse
+
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp.util import run_wsgi_app
+from google.appengine.ext.webapp import template
+
+
+class HostMetaHandler(webapp.RequestHandler):
+ """Renders and serves /.well-known/host-meta.
+
+ TODO: add caching headers
+ """
+
+ def get(self):
+ self.response.headers['Content-Type'] = 'application/xrd+xml'
+ self.response.out.write(template.render(
+ 'templates/host-meta.xrd',
+ # app_identity.get_default_version_hostname() would be better here, but
+ # it doesn't work in dev_appserver since that doesn't set
+ {'lrdd_url': 'https://%s/user?uri={uri}' % os.getenv('HTTP_HOST')}))
+
+
+class UserHandler(webapp.RequestHandler):
+ """Renders and serves /user?uri=...
+
+ TODO: add caching headers
+ """
+
+ def get(self):
+ # parse and validate user uri
+ uri = self.request.get('uri')
+ if not uri:
+ raise webapp.exc.HTTPBadRequest('Missing uri query parameter.')
+
+ scheme, user = urlparse.urlparse(uri)
+ if scheme != 'acct':
+ raise webapp.exc.HTTPBadRequest('URI must start with acct:.')
+
+ try:
+ username, host = user.split('@')
+ assert username, host
+ except ValueError, AssertionError:
+ raise webapp.exc.HTTPBadRequest('Bad user URI: %s' % uri)
+
+ # render template
+ vars = {'uri': uri}
+ vars.update(self.get_template_vars(username, host))
+
+ self.response.headers['Content-Type'] = 'application/xrd+xml'
+ self.response.out.write(template.render('templates/user.xrd', vars))
+
+ def get_template_vars(self, username, host):
+ if host == 'facebook.com':
+ return {
+ 'profile_url': 'http://www.facebook.com/%s' % username,
+ 'picture_url': 'http://graph.facebook.com/%s/picture' % username,
+ 'openid_url': 'http://facebook-openid.appspot.com/%s' % username,
+ }
+ else:
+ raise webapp.exc.HTTPInternalServerError('%s is not yet supported.' % host)
+
+ return vars
+
+
+def main():
+ application = webapp.WSGIApplication(
+ [('/.well-known/host-meta', HostMetaHandler),
+ ('/user', UserHandler),
+ ],
+ debug=appengine_config.DEBUG)
+ run_wsgi_app(application)
+
+
+if __name__ == '__main__':
+ main()
View
22 app.yaml
@@ -0,0 +1,22 @@
+application: webfinger-unofficial
+version: 1
+runtime: python27
+threadsafe: false
+api_version: 1
+default_expiration: 1d
+
+handlers:
+- url: /static
+ static_dir: static
+
+- url: /.well-known/host-meta
+ script: app.py
+ secure: always
+
+- url: /user
+ script: app.py
+ secure: always
+
+- url: /
+ static_files: static/index.html
+ upload: static/index.html
View
6 appengine_config.py
@@ -0,0 +1,6 @@
+"""App Engine settings.
+"""
+
+import os
+DEBUG = os.environ.get('SERVER_SOFTWARE', '').startswith('Development')
+
View
10 templates/host-meta.xrd
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?> <!-- -*- xml -*- -->
+<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
+ xmlns:hm='http://host-meta.net/xrd/1.0'>
+
+ <hm:Host xmlns='http://host-meta.net/xrd/1.0'>example.com</hm:Host>
+
+ <Link rel='lrdd' template='{{ lrdd_url }}'>
+ <Title>Resource Descriptor</Title>
+ </Link>
+</XRD>
View
24 templates/user.xrd
@@ -0,0 +1,24 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
+
+ <Subject>{{ uri }}</Subject>
+ <Alias>{{ profile_url }}</Alias>
+
+ <!-- list of possible link relations:
+ http://code.google.com/p/webfinger/wiki/CommonLinkRelations
+ -->
+ <Link rel='http://webfinger.net/rel/profile-page' type='text/html'
+ href='{{ profile_url }}' />
+ <Link rel='describedby' type='text/html'
+ href='{{ profile_url }}' />
+
+ {% if picture_url %}
+ <Link rel='http://webfinger.net/rel/avatar'
+ href='{{ picture_url }}' />
+ {% endif %}
+
+ {% if openid_url %}
+ <Link rel='http://specs.openid.net/auth/2.0/provider'
+ href='{{ openid_url }}' />
+ {% endif %}
+</XRD>
Please sign in to comment.
Something went wrong with that request. Please try again.