def authenticate_http_request(token=None):
if token:<EOL><INDENT>auth = token<EOL><DEDENT>else:<EOL><INDENT>auth = request.headers.get('<STR_LIT>', None)<EOL><DEDENT>if not auth:<EOL><INDENT>auth = request.cookies.get('<STR_LIT>', None)<EOL>if auth:<EOL><INDENT>auth = unquote_plus(auth)<EOL><DEDENT><DEDENT>log.debug("<STR_LIT>" % auth)<EOL>if not auth:<EOL><INDENT>raise AuthMissingHeaderError('<STR_LIT>')<EOL><DEDENT>parts = auth.split()<EOL>if parts[<NUM_LIT:0>].lower() != '<STR_LIT>':<EOL><INDENT>raise AuthInvalidTokenError('<STR_LIT>')<EOL><DEDENT>elif len(parts) == <NUM_LIT:1>:<EOL><INDENT>raise AuthInvalidTokenError('<STR_LIT>')<EOL><DEDENT>elif len(parts) > <NUM_LIT:2>:<EOL><INDENT>raise AuthInvalidTokenError('<STR_LIT>')<EOL><DEDENT>token = parts[<NUM_LIT:1>]<EOL>return load_auth_token(token)<EOL>
Validate auth0 tokens passed in the request's header, hence ensuring
    that the user is authenticated. Code copied from:
    https://github.com/auth0/auth0-python/tree/master/examples/flask-api

    Return a PntCommonException if failed to validate authentication.
    Otherwise, return the token's payload (Also stored in stack.top.current_user)