diff --git a/pierone/api.py b/pierone/api.py
index 01523d7..06a97d0 100644
--- a/pierone/api.py
+++ b/pierone/api.py
@@ -8,7 +8,7 @@ import time
 
 import requests
 from clickclick import Action
-from zign.api import get_named_token
+from zign.api import get_token
 
 adapter = requests.adapters.HTTPAdapter(pool_connections=10, pool_maxsize=10)
 session = requests.Session()
@@ -52,23 +52,10 @@ class DockerImage(collections.namedtuple('DockerImage', 'registry team artifact
         return '{}/{}/{}:{}'.format(*tuple(self))
 
 
+# all the other paramaters are deprecated, but still here for compatibility
 def docker_login(url, realm, name, user, password, token_url=None, use_keyring=True, prompt=False):
-    token = None  # Make linters happy
-    with Action('Getting OAuth2 token "{}"..'.format(name)) as action:
-        try:
-            token = get_named_token(['uid', 'application.write'],
-                                    realm, name, user, password, url=token_url,
-                                    use_keyring=use_keyring, prompt=prompt)
-        except requests.HTTPError as error:
-            status_code = error.response.status_code
-            if 400 <= status_code < 500:
-                action.fatal_error(
-                    'Authentication Failed ({} Client Error). Check your configuration.'.format(status_code))
-            if 500 <= status_code < 600:
-                action.fatal_error('Authentication Failed ({} Server Error).'.format(status_code))
-            else:
-                action.fatal_error('Authentication Failed ({})'.format(status_code))
-    access_token = token.get('access_token')
+    with Action('Getting OAuth2 token "{}"..'.format(name)):
+        access_token = get_token(name, ['uid', 'application.write'])
     docker_login_with_token(url, access_token)
 
 

Use zign.api.get_token
https://github.com/zalando-stups/zign/pull/41
diff --git a/tests/test_api.py b/tests/test_api.py
index f1ea9c9..1b99794 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -12,10 +12,7 @@ import requests.exceptions
 
 def test_docker_login(monkeypatch, tmpdir):
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
-    response = MagicMock()
-    response.status_code = 200
-    response.json.return_value = {'access_token': '12377'}
-    monkeypatch.setattr('requests.get', MagicMock(return_value=response))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='12377'))
     docker_login('https://pierone.example.org', 'services', 'mytok',
                  'myuser', 'mypass', 'https://token.example.org', use_keyring=False)
     path = os.path.expanduser('~/.docker/config.json')
@@ -36,44 +33,9 @@ def test_docker_login_service_token(monkeypatch, tmpdir):
                 'email': 'no-mail-required@example.org'} == data.get('auths').get('https://pierone.example.org')
 
 
-@pytest.mark.parametrize(
-    "status_code",
-    [
-        (400),
-        (404),
-        (500),
-        (502),
-        (700),  # nonsense status code that should be handled all the same
-    ])
-def test_docker_login_error(monkeypatch, status_code):
-    mock_get = MagicMock()
-    response = MagicMock()
-    response.status_code = status_code
-    mock_get.side_effect = requests.exceptions.HTTPError(response=response)
-    monkeypatch.setattr('tokens.get', mock_get)
-
-    mock_action = MagicMock()
-    mock_action.side_effect = SystemExit(1)
-    monkeypatch.setattr('pierone.api.Action.fatal_error', mock_action)
-    with pytest.raises(SystemExit):
-        docker_login('https://pierone.example.org', None, 'mytok', 'myuser', 'mypass', 'https://token.example.org')
-    mock_action.assert_called_once_with(ANY)
-    call = mock_action.call_args[0]
-    argument = call[0]  # type: str
-    assert argument.startswith("Authentication Failed")
-    assert str(status_code) in argument
-    if 400 <= status_code < 500:
-        assert "Client Error" in argument
-    if 500 <= status_code < 600:
-        assert "Server Error" in argument
-
-
 def test_keep_dockercfg_entries(monkeypatch, tmpdir):
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
-    response = MagicMock()
-    response.status_code = 200
-    response.json.return_value = {'access_token': '12377'}
-    monkeypatch.setattr('requests.get', MagicMock(return_value=response))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='12377'))
     path = os.path.expanduser('~/.docker/config.json')
 
     key = 'https://old.example.org'
diff --git a/tests/test_cli.py b/tests/test_cli.py
index da9efb6..e3eecea 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -28,7 +28,7 @@ def test_login(monkeypatch, tmpdir):
     runner = CliRunner()
 
     monkeypatch.setattr('stups_cli.config.load_config', lambda x: {})
-    monkeypatch.setattr('pierone.api.get_named_token', MagicMock(return_value={'access_token': 'tok123'}))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='tok123'))
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
 
     with runner.isolated_filesystem():
@@ -45,7 +45,7 @@ def test_invalid_url_for_login(monkeypatch, tmpdir):
     response = MagicMock()
 
     monkeypatch.setattr('stups_cli.config.load_config', lambda x: {})
-    monkeypatch.setattr('pierone.api.get_named_token', MagicMock(return_value={'access_token': 'tok123'}))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='tok123'))
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
 
     # Missing Pier One header
@@ -138,7 +138,7 @@ def test_login_given_url_option(monkeypatch, tmpdir):
 
     monkeypatch.setattr('stups_cli.config.load_config', lambda x: {})
     monkeypatch.setattr('stups_cli.config.store_config', store)
-    monkeypatch.setattr('pierone.api.get_named_token', MagicMock(return_value={'access_token': 'tok123'}))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='tok123'))
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
 
     with runner.isolated_filesystem():

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov flake8
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
click==8.1.8
clickclick==20.10.2
coverage==7.8.0
dnspython==2.7.0
exceptiongroup==1.2.2
flake8==7.2.0
idna==3.10
iniconfig==2.1.0
mccabe==0.7.0
packaging==24.2
pluggy==1.5.0
pycodestyle==2.13.0
pyflakes==3.3.1
pytest==8.3.5
pytest-cov==6.0.0
PyYAML==6.0.2
requests==2.32.3
stups-cli-support==1.1.22
-e git+https://github.com/zalando-stups/pierone-cli.git@560cae1b4fc185c7a8aa3a1a50e0a96b2c7dd8e7#egg=stups_pierone
stups-tokens==1.1.19
stups-zign==1.2
tomli==2.2.1
urllib3==2.3.0

name: pierone-cli
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - click==8.1.8
      - clickclick==20.10.2
      - coverage==7.8.0
      - dnspython==2.7.0
      - exceptiongroup==1.2.2
      - flake8==7.2.0
      - idna==3.10
      - iniconfig==2.1.0
      - mccabe==0.7.0
      - packaging==24.2
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.1
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - pyyaml==6.0.2
      - requests==2.32.3
      - stups-cli-support==1.1.22
      - stups-tokens==1.1.19
      - stups-zign==1.2
      - tomli==2.2.1
      - urllib3==2.3.0
prefix: /opt/conda/envs/pierone-cli

tests/test_api.py::test_docker_login tests/test_api.py::test_keep_dockercfg_entries tests/test_cli.py::test_login tests/test_cli.py::test_invalid_url_for_login tests/test_cli.py::test_login_given_url_option
tests/test_api.py::test_docker_login_service_token tests/test_api.py::test_get_latest_tag tests/test_api.py::test_get_latest_tag_IOException tests/test_api.py::test_get_latest_tag_non_json tests/test_api.py::test_image_exists tests/test_api.py::test_image_exists_IOException tests/test_api.py::test_image_exists_but_other_version tests/test_api.py::test_image_not_exists tests/test_api.py::test_get_image_tags tests/test_api.py::test_get_image_tag tests/test_api.py::test_get_image_tag_that_does_not_exist tests/test_cli.py::test_version tests/test_cli.py::test_login_arg_user tests/test_cli.py::test_login_zign_user tests/test_cli.py::test_login_env_user tests/test_cli.py::test_scm_source tests/test_cli.py::test_image tests/test_cli.py::test_tags tests/test_cli.py::test_tags_versions_limit tests/test_cli.py::test_cves tests/test_cli.py::test_no_cves_found tests/test_cli.py::test_latest tests/test_cli.py::test_latest_not_found tests/test_cli.py::test_url_without_scheme
pierone/api.py
pierone/api.py