Here is a GAE proxy that you can call from your iphone app using Facebook connect.
Call it facebookProxy or whatever and add a URL handler on GAE.
Call it from within the iPhone app using:
session = [FBSession sessionForApplication:myApiKey
getSessionProxy:@"http://yourApp.appspot.com/facebookProxy"
delegate:self];
Here is the python code for the proxy. I use a seperate constants file to store the Facebook app keys, so you need to change that to use it.
import cgi
import hashlib
import httplib
import urllib
import logging
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import webapp
from google.appengine.api import users
import Constants
FB_API_HOST="api.facebook.com"
FB_API_PATH="/restserver.php"
def facebook_signature(paramsDict):
"""Compute the signature of a Facebook request"""
sorted = paramsDict.items()
sorted.sort()
trace = ''.join(["%s=%s" % x for x in sorted])
trace += Constants.FB_API_SECRET()
md5 = hashlib.md5()
md5.update(trace)
return md5.hexdigest()
def get_fb_session(auth_token):
"""Request a Facebook session using the given auth_token"""
params={
"api_key":Constants.FB_API_KEY,
"v":"1.0",
"auth_token":auth_token,
"generate_session_secret":"1",
"method":"auth.getSession",
}
params["sig"] = facebook_signature(params)
encoded_params = urllib.urlencode(params)
headers = {
"Content-type":"application/x-www-form-urlencoded",
}
conn = httplib.HTTPConnection(FB_API_HOST)
conn.request("POST", FB_API_PATH, encoded_params, headers)
logging.debug("%s" % encoded_params)
return conn.getresponse()
class FacebookSessionProxy(webapp.RequestHandler):
def get(self):
response = self.response
auth_token = self.request.get('auth_token')
logging.debug("AUTH TOKEN: %s" % auth_token)
if len(auth_token) == 0:
response.set_status(httplib.BAD_REQUEST)
response.out.write("Facebook login error: no auth_token given.")
return
fbResponse = get_fb_session(auth_token)
response.out.write(fbResponse.read())
response.set_status(fbResponse.status, fbResponse.reason)
response.headers['Content-Type'] = fbResponse.getheader('content-type')
# The End
application = webapp.WSGIApplication(
[
('/facebookproxy', FacebookSessionProxy),
],
debug=True)
def main():
logging.getLogger().setLevel(logging.DEBUG)
run_wsgi_app(application)
if __name__ == "__main__":
main()