Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit bce6fe919380adbbbfe57442af52bb7544734d66 1 parent d79322b
Ryan Barrett authored January 16, 2012

Showing 2 changed files with 24 additions and 13 deletions. Show diff stats Hide diff stats

  1. 13  README
  2. 24  app.py
13  README
@@ -8,9 +8,20 @@ http://twitter-webfinger.appspot.com/
8 8
 Feel free to add more!
9 9
 
10 10
 Background on webfinger:
11  
-http://code.google.com/p/webfinger/wiki/WebFingerProtocol
  11
+http://code.google.com/p/webfinger/
12 12
 http://hueniverse.com/2009/09/implementing-webfinger/
13 13
 
  14
+To use this in a webfinger client, you'll need to hard-code exceptions for the
  15
+facebook.com and twitter.com hosts and redirect webfinger HTTP requests to the
  16
+corresponding endpoint above. (The user URI may use either domain, e.g.
  17
+snarfed.org@facebook.com or snarfed.org@facebook-webfinger.appspot.com.)
  18
+
14 19
 Note the app.yaml.* files, one for each App Engine app id. To work on or deploy
15 20
 a specific app id, symlink app.yaml to its app.yaml.xxx file. Likewise, if you
16 21
 add a new site, you'll need to add a corresponding app.yaml.xxx file.
  22
+
  23
+Deploy commands:
  24
+rm -f app.yaml && ln -s app.yaml.twitter app.yaml && \
  25
+  ~/google_appengine/appcfg.py update .
  26
+rm -f app.yaml && ln -s app.yaml.facebook app.yaml && \
  27
+  ~/google_appengine/appcfg.py update .
24  app.py
@@ -20,7 +20,8 @@
20 20
   'facebook-webfinger': 'facebook.com',
21 21
   'twitter-webfinger': 'twitter.com',
22 22
   }
23  
-DOMAIN = APP_ID_DOMAINS[app_identity.get_application_id()]
  23
+APP_ID = app_identity.get_application_id()
  24
+DOMAIN = APP_ID_DOMAINS[APP_ID]
24 25
 # app_identity.get_default_version_hostname() would be better here, but
25 26
 # it doesn't work in dev_appserver since that doesn't set
26 27
 # os.environ['DEFAULT_VERSION_HOSTNAME'].
@@ -57,8 +58,8 @@ def get(self):
57 58
       raise webapp.exc.HTTPBadRequest('Missing uri query parameter.')
58 59
 
59 60
     parsed = urlparse.urlparse(uri)
60  
-    if parsed.scheme != 'acct':
61  
-      raise webapp.exc.HTTPBadRequest('URI must start with acct:.')
  61
+    if parsed.scheme and parsed.scheme != 'acct':
  62
+      raise webapp.exc.HTTPBadRequest('Unsupported URI scheme: %s' % parsed.scheme)
62 63
 
63 64
     try:
64 65
       username, host = parsed.path.split('@')
@@ -66,35 +67,34 @@ def get(self):
66 67
     except ValueError, AssertionError:
67 68
       raise webapp.exc.HTTPBadRequest('Bad user URI: %s' % uri)
68 69
 
69  
-    expected_host = APP_ID_DOMAINS[app_identity.get_application_id()]
70  
-    if host != expected_host:
  70
+    if host not in (HOST, DOMAIN):
71 71
       raise webapp.exc.HTTPBadRequest(
72  
-        'User URI %s has unsupported host %s; expected %s.' %
73  
-        (uri, host, expected_host))
  72
+        'User URI %s has unsupported host %s; expected %s or %s.' %
  73
+        (uri, host, HOST, DOMAIN))
74 74
 
75 75
     # render template
76 76
     vars = {'uri': uri}
77  
-    vars.update(self.get_template_vars(username, host))
  77
+    vars.update(self.get_template_vars(username))
78 78
 
79 79
     self.response.headers['Content-Type'] = 'application/xrd+xml'
80 80
     self.response.headers['Cache-Control'] = 'max-age=300'
81 81
     self.response.out.write(template.render('templates/user.xrd', vars))
82 82
 
83  
-  def get_template_vars(self, username, host):
84  
-    if host == 'facebook.com':
  83
+  def get_template_vars(self, username):
  84
+    if APP_ID == 'facebook-webfinger':
85 85
       return {
86 86
           'profile_url': 'http://www.facebook.com/%s' % username,
87 87
           'picture_url': 'http://graph.facebook.com/%s/picture' % username,
88 88
           'openid_url': 'http://facebook-openid.appspot.com/%s' % username,
89 89
           }
90  
-    elif host == 'twitter.com':
  90
+    elif APP_ID == 'twitter-webfinger':
91 91
       return {
92 92
           'profile_url': 'http://twitter.com/%s' % username,
93 93
           'picture_url':
94 94
             'http://api.twitter.com/1/users/profile_image?screen_name=%s' % username,
95 95
           }
96 96
     else:
97  
-      raise webapp.exc.HTTPInternalServerError('%s is not yet supported.' % host)
  97
+      raise webapp.exc.HTTPInternalServerError('Unknown app id %s.' % APP_ID)
98 98
 
99 99
     return vars
100 100
 

0 notes on commit bce6fe9

Please sign in to comment.
Something went wrong with that request. Please try again.