Repository navigation
fix!: answer FastAPI session guard refusals under error - #39
Merged
Merged
Conversation
RequireUser answered its 401, 403 and recovery refusals as {"detail": ...},
while Django, the permission guard and every other adapter answer
{"error": ...}. All of them now answer {"error": ...}, with the same status
codes and the same error strings. exc.detail still holds the error string.
PermissionHTTPException, which never shipped in a release, is now
GuardHTTPException, since it covers every guard refusal.
BREAKING CHANGE: FastAPI RequireUser refusals (unauthenticated,
insufficient_role, enrollment_required, cross_site_request_blocked) answer
{"error": "<code>"} instead of {"detail": "<code>"}. A client that reads
body.detail must read body.error. They also no longer reach an application's
own HTTPException handler. To change them, register a handler for
GuardHTTPException.
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.
FastAPI's
RequireUseranswered its refusals as{"detail": ...}, while Django, the permission guard and every other adapter answer{"error": ...}. This moves all of them to{"error": ...}. The difference was recorded by a test in #38, which this replaces.Behaviour change for adopters
This changes a response body adopters may read.
{"detail": "unauthenticated"}{"error": "unauthenticated"}{"detail": "insufficient_role"}{"error": "insufficient_role"}{"detail": "enrollment_required"}{"error": "enrollment_required"}{"detail": "cross_site_request_blocked"}{"error": "cross_site_request_blocked"}body.detailon these responses must readbody.error. Status codes and error strings do not change, and Django is unaffected.HTTPExceptionhandler, because the guard's handler for its more specific class is found first. To change them, register a handler forGuardHTTPException. Permission refusals already worked this way.exc.status_codeandexc.detail, which holds the error string.Also changed
PermissionHTTPException, added in #38, is nowGuardHTTPException, since it now covers every guard refusal. #38 is not in a release yet (v0.6.0 is still open as #36), so no released name changes. If #36 merges first, the rename becomes breaking and the commit message needs rewording.Release note
The commit is
fix!:with aBREAKING CHANGE:footer, so release-please should bump the minor version and list this under breaking changes. On a squash merge, keep thefix!:title and the footer in the commit message.Testing
uv run ruff check .,uv run ruff format --check .,uv run mypy: passuv run pytest: 1084 passedseamless verify --adapter-urlwithSEAMLESS_VERIFY_CONTRACTS=content-type-gate, againstseamless-cliandseamless-auth-apimain: passed for the FastAPI and Django reference appsThe adapter specs in the conformance suite do not assert these error bodies, so that run shows nothing else regressed. The new shape is covered by the unit tests, including a mounted app and an application handler.
Not in this PR
BearerHTTPException) still sit underdetailunless the adopter callsadd_bearer_error_handler.build/python-adapter.mdxinseamless-auth-docsstill says the package has no role guard.