def POST(self): fb_data = fb.parse_signed_request(web.input()['signed_request']) if not fb_data: raise web.forbidden() gettext.translation('messages', localedir, languages=[fb_data['user']['locale'], 'en_US']).install(True) if not fb_data.get('user_id'): return "<script> top.location.href='" + fb.oauth_login_url( ) + "'</script>" res = fb.call('fql', args={ 'q': "SELECT pic_cover FROM user WHERE uid='{}'".format( fb_data['user_id']), 'access_token': fb_data['oauth_token'] }) cover = fb.get_biggest_image(res['data'][0]['pic_cover']['cover_id']) flipped_cover = flip_url(cover) tracking_id = os.environ.get('TRACKING_ID', '') return render.index(fb_data, cover, flipped_cover, web.ctx.host, tracking_id, _, DEBUG)
def test_facebook_signed_request_parsing(self): """ Tests the decoding of facebooks signed request Should return {"0":"payload"} """ params = parse_signed_request(SIGNED_REQUEST, SECRET_KEY) self.assertEqual(len(params),2) self.assertEqual(params["0"], 'payload')
def POST(self): fb_data = fb.parse_signed_request(web.input()['signed_request']) if not fb_data: raise web.forbidden() gettext.translation('messages', localedir, languages=[fb_data['user']['locale'], 'en_US']).install(True) if not fb_data.get('user_id'): return "<script> top.location.href='" + fb.oauth_login_url() + "'</script>" res = fb.call('fql', args={'q': "SELECT pic_cover FROM user WHERE uid='{}'".format(fb_data['user_id']), 'access_token': fb_data['oauth_token']}) cover = fb.get_biggest_image(res['data'][0]['pic_cover']['cover_id']) flipped_cover = flip_url(cover) tracking_id = os.environ.get('TRACKING_ID', '') return render.index(fb_data, cover, flipped_cover, web.ctx.host, tracking_id, _, DEBUG)
def process_request(self, request): signed_request = request.REQUEST.get("signed_request", '') if signed_request: #logger.debug('facebook request') try: facebook_params = parse_signed_request(signed_request, secret_key) except: pass # TO DEAL WITH if facebook_params.get("user_id", ''): ''' User has come through facebook and is logged in get user model ''' request.fb_user, created = FbUser.objects.get_or_create(user_id=facebook_params['user_id']) else: ''' User has come through facebook but isn't logged in ''' def facebook_return(request): return "<script>top.location.href='%s';</script>" % getattr(settings, 'FACEBOOK_AUTH_URL') return HttpResponse(facebook_return(request)) else: ''' User has come through main webapp site. User mocked facebook details to maintain compatibility ''' if not getattr(settings, 'DEBUG', False): return HttpResponseRedirect(app_url) request.fb_user, created = FbUser.objects.get_or_create(user_id=-1)