I am trying to decrypt facebook signed_request in order to send the registration form to unauthorized users. My code is as follows:
def parse_signed_request(sr):
encoded_sig, payload = sr.split('.', 2)
data = json.loads(base64.b64decode( payload.replace('-_', '+/') ))
if not data['algorithm'].upper() == 'HMAC-SHA256':
raise ValueError('unknown algorithm {0}'.format(data['algorithm']))
return None
h = hmac.new(FB_APP_SECRET, digestmod=hashlib.sha256)
h.update(payload)
expected_sig = urlsafe_b64encode(h.digest()).replace('=', '')
if encoded_sig != expected_sig:
raise ValueError('bad signature')
return None
return data
My problem is that, as in the case of this code, it works successfully for a user who has already registered, but for a user who is not logged in, I get an "Invalid filling" error for b64decode. However, if I fill the payload with the '=' signs, then all users pass the authorization as βlogged inβ, regardless of whether they are valid.
Can anyone help me here?
nct25 source
share