Repository navigation
refactor: read the token challenge from headers - #371
Conversation
Tell invalid tokens of public reads from other rejections by the WWW-Authenticate header of the exception, not its www_authenticate attribute, so that FOCA can move the challenge to its generic headers (foca#710). Works with FOCA 0.21 and after that change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR makes invalid-token detection representation-agnostic by reading and parsing Sequence diagram for header-based invalid-token detectionsequenceDiagram
participant Validation as validate_token
participant Permissions as _is_invalid_token
participant Error as Unauthorized
participant Parser as WWWAuthenticate.from_header
Validation->>Permissions: _is_invalid_token(exc)
Permissions->>Error: get_headers()
Error-->>Permissions: WWW-Authenticate headers
loop each response header
Permissions->>Parser: from_header(value)
Parser-->>Permissions: challenge
alt Bearer challenge with error=invalid_token
Permissions-->>Validation: True
end
end
Permissions-->>Validation: False
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Linked issues
#370 refactor: read the token challenge from headers · 1 of 1 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Read the challenge from exception headers, working with FOCA 0.21 and after foca#710. | ✅ Met | _is_invalid_token() checks get_headers() and tests cover both Werkzeug's www_authenticate attribute and FOCA token errors. |
Sourcery assessment
Needs a human reviewer. The Bearer challenge determines whether a token failure is classified as an invalid credential or another validation failure; misparsing it could change how requests with rejected tokens are handled. Reverting removes the new header-based classification, but any misclassified requests handled before the revert cannot be undone.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #371 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 3259 3265 +6
=========================================
+ Hits 3259 3265 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #370
Summary
_is_invalid_token()now reads the RFC 6750 challenge from the headers the exception produces (get_headers()), not from itswww_authenticateattribute. It works with FOCA 0.21, which keeps the challenge in the attribute, and after elixir-cloud-aai/foca#710, which moves it to FOCA's genericheaders. This unblocks foca#710. No behaviour change: FOCA sends only Bearer challenges, and only those count now.How it was verified
foca.errors.Unauthorizedondevproduces it: 10 passed.pytest tests/test_access_control.py tests/test_app.py tests/test_issuers.py: 408 passed. Full suite: 726 passed, 1 failed locally (test_chart.py::test_config_change_restarts_app, chart dependencies not built here; unrelated).ruff check,ruff format --check(0.17.3),mypy .: passed.Declined review findings
WWWAuthenticate.from_headerreads one challenge per header value, strictly: several challenges packed into one value, or an upper-case parameter name, aren't recognised. Kept in step with FOCA's own_has_invalid_token_challenge(), which has the same limits; FOCA sends one challenge per header. A miss errs on the safe side (the read stays anonymous).Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Read token validation challenges from response headers to support current and legacy FOCA error formats.
Bug Fixes:
Enhancements:
Tests: