Created
July 26, 2010 09:33
-
-
Save emre/490358 to your computer and use it in GitHub Desktop.
facebook'tan GET olarak donen JSON bilgisinin dogrulugunu kontrol eder.
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
# -*- coding: utf8 -*- | |
import hashlib | |
class FacebookApiSessionValidatorException(Exception): | |
pass | |
class FacebookApiSessionValidator(object): | |
def __init__(self, application_secret, session): | |
self.application_secret = application_secret | |
self.session = session | |
def validate(self): | |
hash = "" | |
for key in sorted(self.session): | |
if key != 'sig': hash += "%s=%s" % (key, self.session.get(key)) | |
hash += self.application_secret | |
if self.getmd5(hash) != self.session.get("sig"): | |
raise FacebookApiSessionValidatorException(u"invalid session") | |
return True | |
def getmd5(self, value = None): | |
hash = hashlib.md5(value) | |
return hash.hexdigest() | |
""" | |
example usage | |
facebook_api_object = { | |
"session_key":"foo", | |
"uid":"user_id", | |
"expires":0, | |
"secret":"foo", | |
"access_token":"foo", | |
"sig":"foo" | |
} | |
validateSession = FacebookApiSessionValidator("[my_facebook_application's_secret]", facebook_api_object) | |
print validateSession.validate() | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment