import base64


def base64url_encode(msg):
    """
    Encode a message to base64 based on JWT spec, Appendix B.
    "Notes on implementing base64url encoding without padding"
    """
    normalb64 = base64.urlsafe_b64encode(msg)
    return normalb64.rstrip(b'=')