Created
May 26, 2009 19:22
-
-
Save landonf/118238 to your computer and use it in GitHub Desktop.
A simple appengine-based facebook request signer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.appengine.ext import webapp | |
import md5 | |
# XXX Facebook private application key | |
APP_KEY = "AAAAAAAAAAAAAAAAAAAAAAAAA" | |
class FacebookRequestSigner(webapp.RequestHandler): | |
def get(self): | |
method = self.request.get("method") | |
# Only sign createToken/getSession requests | |
if (method != "auth.getSession" and method != "auth.createToken"): | |
self.error(401) | |
self.response.out.write("Can not sign method %s" % method) | |
return | |
# Compute the signature | |
canonical = "" | |
for key in sorted(self.request.arguments()): | |
canonical += "%s=%s" % (key, self.request.get(key)) | |
canonical += APP_KEY | |
digest = md5.new(canonical.encode("utf-8")) | |
self.response.headers['Content-Type'] = 'text/plain' | |
self.response.out.write(digest.hexdigest()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment