class_docstr: Retrieve token via 401 response and add Authorization: Bearer header.
      
class_docstr_tok: ["Retrieve","token","via","401","response","and","add","Authorization",":","Bearer","header","."]
code: def authenticate(self, url, credential, session, update=False):
      if credential:
          lgr.warning(
              "Argument 'credential' specified, but it will be ignored: %s",
              credential,
          )
      response = session.head(url)
      status = response.status_code
      if status == 200:
          lgr.debug("No authorization needed for %s", url)
          return
      if status != 401:
          raise DownloadError(
              "Expected 200 or 401 but got {} from {}".format(
                  status, url
              )
          )
  
      lgr.debug("Requesting authorization token for %s", url)
      # TODO: it is not RFC 2068 Section 2 format, but a custom
      # <type> realm=<realm>[, charset="UTF-8"]
      # see TODO/harmonize with  process_www_authenticate
      auth_parts = parse_dict_header(
          response.headers["www-authenticate"]
      )
      auth_url = "{}?service={}&scope={}".format(
          auth_parts["Bearer realm"],
          auth_parts["service"],
          auth_parts["scope"],
      )
      auth_response = session.get(auth_url)
      try:
          auth_info = auth_response.json()
      except ValueError as e:
          raise DownloadError(
              "Failed to get information from {}".format(auth_url)
          ) from e
      session.headers["Authorization"] = "Bearer " + auth_info["token"]
  
imports: import re
  import requests
  import requests.auth
  from requests.utils import parse_dict_header
  import io
  from time import sleep
  from ..None import __version__
  from ..utils import ensure_list_from_str, ensure_dict_from_str, ensure_bytes
  from ..dochelpers import borrowkwargs
  from ..ui import ui
  from ..utils import auto_repr
  from ..support.network import get_url_filename
  from ..support.network import get_response_disposition_filename
  from ..support.network import rfc2822_to_epoch
  from ..support.cookies import cookies_db
  from ..support.status import FileStatus
  from ..support.exceptions import AccessDeniedError, AccessFailedError, CapturedException, DownloadError, UnhandledRedirectError
  from .base import Authenticator
  from .base import BaseDownloader, DownloaderSession
  from logging import getLogger
  from ..log import LoggerHelper
label_desc: Use image node_id 1 for calling the HTTPAnonBearerTokenAuthenticator obj's underlying member method code with example usage: obj.authenticate(url, credential, session, update) without return types