import hmac


def is_authenticated(request, secret):
    """
    Verify whether the user is authenticated

    Args:
        request (tornado.httputil.HTTPRequest): The request
        secret (str): The secret to use for authentication
    """
    # See https://api.slack.com/authentication/verifying-requests-from-slack for more info
    timestamp = request.headers["X-Slack-Request-Timestamp"]
    basestring = f"v0:{timestamp}:{request.body.decode()}".encode()
    digest = (
        "v0="
        + hmac.new(key=secret.encode(), msg=basestring, digestmod="sha256").hexdigest()
    ).encode()
    signature = request.headers["X-Slack-Signature"].encode()
    return hmac.compare_digest(digest, signature)