'validate that a Macaroon is understood by and was signed by this server.
Args:
macaroon(pymacaroons.Macaroon): The macaroon to validate
type_string(str): The kind of token required (e.g. "access",
"delete_pusher")
verify_expiry(bool): Whether to verify whether the macaroon has expired.
user_id (str): The user_id required'

def validate_macaroon(self, macaroon, type_string, verify_expiry, user_id):

    v = pymacaroons.Verifier()
    v.satisfy_exact('gen    =    1')
    v.satisfy_exact(('type    =    ' + type_string))
    v.satisfy_exact(('user_id    =    %s' % user_id))
    v.satisfy_exact('guest    =    true')
    if verify_expiry:
        v.satisfy_general(self._verify_expiry)
    else:
        v.satisfy_general((lambda c: c.startswith('time    <    ')))
    v.satisfy_general((lambda c: c.startswith('nonce    =    ')))
    v.verify(macaroon, self.hs.config.macaroon_secret_key)
