code: def authenticate(self,
                       username=None, password=None,
                       actions=None, response=None,
                       authorization=None):
          if response is None:
              with warnings.catch_warnings():
                  _ignore_warnings(self)
                  response = self._sessions[0].get(self._base_url, verify=self._tlsverify)
          if response.ok:
              return None
          if response.status_code != requests.codes.unauthorized:
              raise exceptions.DXFUnexpectedStatusCodeError(response.status_code,
                                                            requests.codes.unauthorized)
          if self._insecure:
              raise exceptions.DXFAuthInsecureError()
          parsed = www_authenticate.parse(response.headers['www-authenticate'])
          if username is not None and password is not None:
              headers = {
                  'Authorization': 'Basic ' + base64.b64encode(_to_bytes_2and3(username + ':' + password)).decode('utf-8')
              }
          elif authorization is not None:
              headers = {
                  'Authorization': authorization
              }
          else:
              headers = {}
          if 'bearer' in parsed:
              info = parsed['bearer']
              if actions and self._repo:
                  scope = 'repository:' + self._repo + ':' + ','.join(actions)
              elif 'scope' in info:
                  scope = info['scope']
              else:
                  scope = ''
              url_parts = list(urlparse.urlparse(info['realm']))
              query = urlparse.parse_qs(url_parts[4])
              query.update({
                  'service': info['service'],
                  'scope': scope
              })
              url_parts[4] = urlencode(query, True)
              url_parts[0] = 'https'
              if self._auth_host:
                  url_parts[1] = self._auth_host
              auth_url = urlparse.urlunparse(url_parts)
              with warnings.catch_warnings():
                  _ignore_warnings(self)
                  r = self._sessions[0].get(auth_url, headers=headers, verify=self._tlsverify)
              _raise_for_status(r)
              rjson = r.json()
              self.token = rjson['access_token'] if 'access_token' in rjson else rjson['token']
              return self._token
          self._headers = headers
          return None