'parse signed request when using in-site app.
Returns:
dict object like { \'uid\': 12345, \'access_token\': \'ABC123XYZ\', \'expires\': unix-timestamp },
or None if parse failed.'

def parse_signed_request(self, signed_request):

    def _b64_normalize(s):
        appendix = ('=' * (4 - (len(s) % 4)))
        return (s.replace('-', '+').replace('_', '/') + appendix)
    sr = str(signed_request)
    logging.info(('parse    signed    request:    %s' % sr))
    (enc_sig, enc_payload) = sr.split('.', 1)
    sig = base64.b64decode(_b64_normalize(enc_sig))
    data = _parse_json(base64.b64decode(_b64_normalize(enc_payload)))
    if (data['algorithm'] != u'HMAC-SHA256'):
        return None
    expected_sig = hmac.new(self.client_secret, enc_payload, hashlib.sha256).digest()
    if (expected_sig == sig):
        data.user_id = data.uid = data.get('user_id', None)
        data.access_token = data.get('oauth_token', None)
        expires = data.get('expires', None)
        if expires:
            data.expires = data.expires_in = (time.time() + expires)
        return data
    return None
