Repository navigation
Not authenticated for an APIRouteAuthenticatedRule: 401 (WWW-Authenticate: Bearer), not 403 (v1.29.0) - #195
Merged
Merged
Conversation
…cate: Bearer), not 403 (v1.29.0) A client can tell a lost login from a refused access. Also: a blank authenticationRealm defaults to API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rror in the CHANGELOG isNotAuthenticatedRefusal checks all of a route's APIRouteAuthenticatedRules, not only the first rule refusing the request: a route's own rules come before its module's global ones. failedRule removed (no longer needed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #195 +/- ##
=======================================
Coverage 95.67% 95.68%
=======================================
Files 75 75
Lines 25775 25784 +9
=======================================
+ Hits 24661 24671 +10
+ Misses 1114 1113 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Why
A request refused by a route's rules was always answered
403, whether it was not authenticated (no credential, or an invalid or expired token) or authenticated but refused. A client couldn't tell a lost login from a refused access.Also, the refusal message was a
payloadDynamic, which is dropped for a route that doesn't return aString. The client then got shelf's default body,Forbidden.Changes
APIRouteHandler.call: when the rules refuse a request that isn't authenticated, and any of the route'sAPIRouteAuthenticatedRules (or subclasses, likeAPIRoutePermissionTypeRule) refuses it, the response requires authentication. This holds whatever the order of the rules: a route's own rules come before its module's global ones, so another rule may refuse it first. The response is:401WWW-Authenticate: Bearer realm="API"UNAUTHORIZED: Not authenticated, sent aserror, so it is kept whatever the route returnsBearer, not the defaultBasic: browsers show no username/password prompt.403(UNAUTHORIZED: Rules issues ...).APIRouteHandler.isUnauthenticatedRefusal(request).APIRouteAuthenticatedRule.isAuthenticated(request).APIServer): a blankauthenticationRealmnow defaults toAPI. It checked the authentication type instead.Compatibility
403from a rule refusal as "not logged in" now also needs to handle401.APIRoot.call/doCall): for this refusal the message is now theAPIResponse.error; it used to be thepayload. The response also hasrequiresAuthenticationset, withauthenticationTypeBearer.Tests
bones_api_cov_server_http_test.dart:401,WWW-Authenticate: Bearer realm="API", error body403, noWWW-Authenticate401APIbones_api_cov_root_test.dart: the not-authenticated refusal requiresBearerauthentication.ensure_build, which fails on a dirty tree; it passes after the commit.🤖 Generated with Claude Code