import base64


def b64url_decode(data):
    """Decode data encoded as base64-URL"""
    datalen = len(data)
    # Recover base64 padding
    if datalen % 4 == 3:
        data += '='
    elif datalen % 4 == 2:
        data += '=='
    return base64.b64decode(data, altchars='-_')