Skip to content

refactor: remove the authtoken endpoint support - #22

Merged
cigamit merged 1 commit into
ctrliq:mainfrom
blaipr:refactor/remove-authtoken
Sep 13, 2026
Merged

refactor: remove the authtoken endpoint support#22
cigamit merged 1 commit into
ctrliq:mainfrom
blaipr:refactor/remove-authtoken

Conversation

@blaipr

@blaipr blaipr commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

authtoken/ no longer exists on the platform. Grepping awx/api/urls/ and awx/api/views/ in ctrliq/ascender returns nothing for it: the endpoint went when the v1 API did, and the client has been carrying a page, a resource entry and three helpers pointed at a 404.

Removed:

  • ascenderkit/api/pages/authtoken.py and its star import in pages/__init__.py
  • resources._authtoken
  • Base.get_authtoken, Base.load_authtoken and the load_default_authtoken alias, plus the two imports in base.py left unused by their removal

ascender-shell used load_authtoken() as the fallback when uses_sessions() came back false. That path could only ever have produced a confusing 404, so it now raises UnexpectedAscenderState naming what was actually missing:

{api_base_path}login/ did not answer 200. The authtoken endpoint this
used to fall back to no longer exists on the platform.

Session and OAuth2 token authentication are untouched, and they are what the CLI and the library have used throughout.

While checking this I compared every top-level collection endpoint in resources.py against the routes in ctrliq/ascender's awx/api/urls/. authtoken was the only one with no match, so nothing else needs the same treatment.

Verified with black --check, flake8 and the unit suite, 355 passing.

`authtoken/` no longer exists on the platform. Grepping `awx/api/urls/` and
`awx/api/views/` in `ctrliq/ascender` returns nothing for it: the endpoint went
when the v1 API did, and the client has been carrying a page, a resource entry
and three helpers pointed at a 404.

Removed:

- `ascenderkit/api/pages/authtoken.py` and its star import in `pages/__init__.py`
- `resources._authtoken`
- `Base.get_authtoken`, `Base.load_authtoken` and the `load_default_authtoken`
  alias, plus the two imports in `base.py` left unused by their removal

`ascender-shell` used `load_authtoken()` as the fallback when `uses_sessions()`
came back false. That path could only ever have produced a confusing 404, so it
now raises `UnexpectedAscenderState` naming what was actually missing:

    {api_base_path}login/ did not answer 200. The authtoken endpoint this
    used to fall back to no longer exists on the platform.

Session and OAuth2 token authentication are untouched, and they are what the CLI
and the library have used throughout.

While checking this I compared every top-level collection endpoint in
`resources.py` against the routes in `ctrliq/ascender`'s `awx/api/urls/`.
`authtoken` was the only one with no match, so nothing else needs the same
treatment.

Verified with `black --check`, `flake8` and the unit suite, 355 passing.
@ciq-it-service-account

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cigamit
cigamit merged commit ec4fd12 into ctrliq:main Sep 13, 2026
1 check passed
blaipr added a commit to blaipr/ascender-kit that referenced this pull request Sep 13, 2026
`Base.get_oauth2_token` builds a fake request so it can borrow `HTTPBasicAuth` to compute an `Authorization` header:

```python
req = collections.namedtuple('req', 'headers')({})
HTTPBasicAuth(client_id, client_secret)(req)
```

`HTTPBasicAuth.__call__` takes a `PreparedRequest`, sets `r.headers['Authorization']` and returns `r`. A namedtuple with a `headers` attribute happens to survive that, because `__call__` touches nothing else, but it is not what the interface asks for and it breaks the moment requests reads anything more from the object it is handed.

It is a real `PreparedRequest` now, with its headers initialised the way `prepare_headers` does:

```python
req = PreparedRequest()
req.headers = CaseInsensitiveDict()
HTTPBasicAuth(client_id, client_secret)(req)
```

Same cost, no reimplementation of the base64 and encoding handling that `requests` already does correctly, and `collections` is no longer imported at all since this was its only use.

Checked that the header is byte-identical between the two:

```
old header: Basic dXNlcjpwYTU1
new header: Basic dXNlcjpwYTU1
identical: True
```

`headers` also becomes a `CaseInsensitiveDict` rather than a plain one, which is what the other two branches of this method already hand to `connection.post`, so the three paths now agree.

Two diagnostics retired, and `ty` reports nothing further about `HTTPBasicAuth`.

Note for whoever merges: ctrliq#22 removes three methods from this file, immediately above the one changed here, so whichever lands second needs a rebase.

Verified with `black --check`, `flake8` and the unit suite, 355 passing.
cigamit pushed a commit that referenced this pull request Sep 13, 2026
`Base.get_oauth2_token` builds a fake request so it can borrow `HTTPBasicAuth` to compute an `Authorization` header:

```python
req = collections.namedtuple('req', 'headers')({})
HTTPBasicAuth(client_id, client_secret)(req)
```

`HTTPBasicAuth.__call__` takes a `PreparedRequest`, sets `r.headers['Authorization']` and returns `r`. A namedtuple with a `headers` attribute happens to survive that, because `__call__` touches nothing else, but it is not what the interface asks for and it breaks the moment requests reads anything more from the object it is handed.

It is a real `PreparedRequest` now, with its headers initialised the way `prepare_headers` does:

```python
req = PreparedRequest()
req.headers = CaseInsensitiveDict()
HTTPBasicAuth(client_id, client_secret)(req)
```

Same cost, no reimplementation of the base64 and encoding handling that `requests` already does correctly, and `collections` is no longer imported at all since this was its only use.

Checked that the header is byte-identical between the two:

```
old header: Basic dXNlcjpwYTU1
new header: Basic dXNlcjpwYTU1
identical: True
```

`headers` also becomes a `CaseInsensitiveDict` rather than a plain one, which is what the other two branches of this method already hand to `connection.post`, so the three paths now agree.

Two diagnostics retired, and `ty` reports nothing further about `HTTPBasicAuth`.

Note for whoever merges: #22 removes three methods from this file, immediately above the one changed here, so whichever lands second needs a rebase.

Verified with `black --check`, `flake8` and the unit suite, 355 passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants