Permalink
Browse files

support the appspot.com domain in user URIs as well as the primary do…

…main, e.g.

both facebook-webfinger.appspot.com and facebook.com.
  • Loading branch information...
1 parent d79322b commit bce6fe919380adbbbfe57442af52bb7544734d66 Ryan Barrett committed Jan 17, 2012
Showing with 24 additions and 13 deletions.
  1. +12 −1 README
  2. +12 −12 app.py
View
13 README
@@ -8,9 +8,20 @@ http://twitter-webfinger.appspot.com/
Feel free to add more!
Background on webfinger:
-http://code.google.com/p/webfinger/wiki/WebFingerProtocol
+http://code.google.com/p/webfinger/
http://hueniverse.com/2009/09/implementing-webfinger/
+To use this in a webfinger client, you'll need to hard-code exceptions for the
+facebook.com and twitter.com hosts and redirect webfinger HTTP requests to the
+corresponding endpoint above. (The user URI may use either domain, e.g.
+snarfed.org@facebook.com or snarfed.org@facebook-webfinger.appspot.com.)
+
Note the app.yaml.* files, one for each App Engine app id. To work on or deploy
a specific app id, symlink app.yaml to its app.yaml.xxx file. Likewise, if you
add a new site, you'll need to add a corresponding app.yaml.xxx file.
+
+Deploy commands:
+rm -f app.yaml && ln -s app.yaml.twitter app.yaml && \
+ ~/google_appengine/appcfg.py update .
+rm -f app.yaml && ln -s app.yaml.facebook app.yaml && \
+ ~/google_appengine/appcfg.py update .
View
24 app.py
@@ -20,7 +20,8 @@
'facebook-webfinger': 'facebook.com',
'twitter-webfinger': 'twitter.com',
}
-DOMAIN = APP_ID_DOMAINS[app_identity.get_application_id()]
+APP_ID = app_identity.get_application_id()
+DOMAIN = APP_ID_DOMAINS[APP_ID]
# app_identity.get_default_version_hostname() would be better here, but
# it doesn't work in dev_appserver since that doesn't set
# os.environ['DEFAULT_VERSION_HOSTNAME'].
@@ -57,44 +58,43 @@ def get(self):
raise webapp.exc.HTTPBadRequest('Missing uri query parameter.')
parsed = urlparse.urlparse(uri)
- if parsed.scheme != 'acct':
- raise webapp.exc.HTTPBadRequest('URI must start with acct:.')
+ if parsed.scheme and parsed.scheme != 'acct':
+ raise webapp.exc.HTTPBadRequest('Unsupported URI scheme: %s' % parsed.scheme)
try:
username, host = parsed.path.split('@')
assert username, host
except ValueError, AssertionError:
raise webapp.exc.HTTPBadRequest('Bad user URI: %s' % uri)
- expected_host = APP_ID_DOMAINS[app_identity.get_application_id()]
- if host != expected_host:
+ if host not in (HOST, DOMAIN):
raise webapp.exc.HTTPBadRequest(
- 'User URI %s has unsupported host %s; expected %s.' %
- (uri, host, expected_host))
+ 'User URI %s has unsupported host %s; expected %s or %s.' %
+ (uri, host, HOST, DOMAIN))
# render template
vars = {'uri': uri}
- vars.update(self.get_template_vars(username, host))
+ vars.update(self.get_template_vars(username))
self.response.headers['Content-Type'] = 'application/xrd+xml'
self.response.headers['Cache-Control'] = 'max-age=300'
self.response.out.write(template.render('templates/user.xrd', vars))
- def get_template_vars(self, username, host):
- if host == 'facebook.com':
+ def get_template_vars(self, username):
+ if APP_ID == 'facebook-webfinger':
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,
}
- elif host == 'twitter.com':
+ elif APP_ID == 'twitter-webfinger':
return {
'profile_url': 'http://twitter.com/%s' % username,
'picture_url':
'http://api.twitter.com/1/users/profile_image?screen_name=%s' % username,
}
else:
- raise webapp.exc.HTTPInternalServerError('%s is not yet supported.' % host)
+ raise webapp.exc.HTTPInternalServerError('Unknown app id %s.' % APP_ID)
return vars

0 comments on commit bce6fe9

Please sign in to comment.