def parse_signed_request(signed_request, app_secret):
 try:
  l = signed_request.split('.', 2)
  encoded_sig = str(l[0])
  payload = str(l[1])
  sig = base64.urlsafe_b64decode((encoded_sig + ('=' * ((4 - (len(encoded_sig) % 4)) % 4))))
  data = base64.urlsafe_b64decode((payload + ('=' * ((4 - (len(payload) % 4)) % 4))))
 except IndexError:
  return False
 except TypeError:
  return False
 data = _parse_json(data)
 if (data.get('algorithm', '').upper() != 'HMAC-SHA256'):
  return False
 app_secret = app_secret.encode('ascii')
 payload = payload.encode('ascii')
 expected_sig = hmac.new(app_secret, msg=payload, digestmod=hashlib.sha256).digest()
 if (sig != expected_sig):
  return False
 return data

def parse_signed_request ( signed_request , app_secret ) : try : l = signed_request . split ( '.' , 2 ) encoded_sig = str ( l [ 0 ] ) payload = str ( l [ 1 ] ) sig = base64 . urlsafe_b64decode ( ( encoded_sig + ( '=' * ( ( 4 - ( len ( encoded_sig ) % 4 ) ) % 4 ) ) ) ) data = base64 . urlsafe_b64decode ( ( payload + ( '=' * ( ( 4 - ( len ( payload ) % 4 ) ) % 4 ) ) ) ) except IndexError : return False except TypeError : return False data = _parse_json ( data ) if ( data . get ( 'algorithm' , '' ) . upper ( ) != 'HMAC-SHA256' ) : return False app_secret = app_secret . encode ( 'ascii' ) payload = payload . encode ( 'ascii' ) expected_sig = hmac . new ( app_secret , msg = payload , digestmod = hashlib . sha256 ) . digest ( ) if ( sig != expected_sig ) : return False return data
return dictionary with signed request data .