refactor: remove the authtoken endpoint support - #22
Merged
Conversation
`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.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This was referenced Sep 12, 2026
cigamit
approved these changes
Sep 13, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
authtoken/no longer exists on the platform. Greppingawx/api/urls/andawx/api/views/inctrliq/ascenderreturns 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.pyand its star import inpages/__init__.pyresources._authtokenBase.get_authtoken,Base.load_authtokenand theload_default_authtokenalias, plus the two imports inbase.pyleft unused by their removalascender-shellusedload_authtoken()as the fallback whenuses_sessions()came back false. That path could only ever have produced a confusing 404, so it now raisesUnexpectedAscenderStatenaming what was actually missing: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.pyagainst the routes inctrliq/ascender'sawx/api/urls/.authtokenwas the only one with no match, so nothing else needs the same treatment.Verified with
black --check,flake8and the unit suite, 355 passing.