def parse_signed_request(signed_request, app_secret):
try:<EOL><INDENT>encoded_sig, payload = map(str, signed_request.split("<STR_LIT:.>", <NUM_LIT:1>))<EOL>sig = base64.urlsafe_b64decode(<EOL>encoded_sig + "<STR_LIT:=>" * ((<NUM_LIT:4> - len(encoded_sig) % <NUM_LIT:4>) % <NUM_LIT:4>)<EOL>)<EOL>data = base64.urlsafe_b64decode(<EOL>payload + "<STR_LIT:=>" * ((<NUM_LIT:4> - len(payload) % <NUM_LIT:4>) % <NUM_LIT:4>)<EOL>)<EOL><DEDENT>except IndexError:<EOL><INDENT>return False<EOL><DEDENT>except TypeError:<EOL><INDENT>return False<EOL><DEDENT>except binascii.Error:<EOL><INDENT>return False<EOL><DEDENT>data = json.loads(data.decode("<STR_LIT:ascii>"))<EOL>if data.get("<STR_LIT>", "<STR_LIT>").upper() != "<STR_LIT>":<EOL><INDENT>return False<EOL><DEDENT>app_secret = app_secret.encode("<STR_LIT:ascii>")<EOL>payload = payload.encode("<STR_LIT:ascii>")<EOL>expected_sig = hmac.new(<EOL>app_secret, msg=payload, digestmod=hashlib.sha256<EOL>).digest()<EOL>if sig != expected_sig:<EOL><INDENT>return False<EOL><DEDENT>return data<EOL>
Return dictionary with signed request data.

    We return a dictionary containing the information in the
    signed_request. This includes a user_id if the user has authorised
    your application, as well as any information requested.

    If the signed_request is malformed or corrupted, False is returned.