Repository navigation
Authentication: Bearer header without the Web API module no longer returns 500 (2.4.x) - #899
Merged
KrzysztofPajak merged 1 commit intoOct 11, 2026
Conversation
KrzysztofPajak
deleted the
fix/2.4.x-api-authentication-without-scheme
branch
October 11, 2026 09:28
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.
Type: bugfix
Backport of #888 to 2.4.x.
Issue
When the Web API module (
Grand.Module.Api) is off, its JwtBearer schemes (Bearer,FrontAuthentication) are not registered. A request that carries anAuthorization: Bearer ...header to any storefront or admin URL still reachesApiAuthenticationService.GetAuthenticatedCustomerand fails with HTTP 500 ("No authentication handler is registered for the scheme 'Bearer'"). Clients, crawlers or tools that send such a header get an error page instead of the normal response.Solution
Before it authenticates,
ApiAuthenticationServicechecks throughIAuthenticationSchemeProviderthat the scheme is registered. If it is not, the request is treated as one without an API token. With the module on, nothing changes. The change is a cherry-pick of the squashed #888 with no other edits.Breaking changes
The
ApiAuthenticationServiceconstructor gains anIAuthenticationSchemeProviderparameter. Only subclasses are affected, because the service is resolved through DI.Testing
dotnet test src/Tests/Grand.Business.Authentication.Tests: 45/45 pass, including the new tests for theBearerandFrontAuthenticationschemes when they are not registered.curl -i -H "Authorization: Bearer x" https://host/returns the page, and/Adminredirects to the login page.