Skip to content

Authentication: Bearer header without the Web API module no longer returns 500 (2.4.x) - #899

Merged
KrzysztofPajak merged 1 commit into
2.4.xfrom
fix/2.4.x-api-authentication-without-scheme
Oct 11, 2026
Merged

KrzysztofPajak merged 1 commit into
2.4.xfrom
fix/2.4.x-api-authentication-without-scheme

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

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 an Authorization: Bearer ... header to any storefront or admin URL still reaches ApiAuthenticationService.GetAuthenticatedCustomer and 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, ApiAuthenticationService checks through IAuthenticationSchemeProvider that 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 ApiAuthenticationService constructor gains an IAuthenticationSchemeProvider parameter. Only subclasses are affected, because the service is resolved through DI.

Testing

  1. dotnet test src/Tests/Grand.Business.Authentication.Tests: 45/45 pass, including the new tests for the Bearer and FrontAuthentication schemes when they are not registered.
  2. With the module off, curl -i -H "Authorization: Bearer x" https://host/ returns the page, and /Admin redirects to the login page.
  3. With the module on, Web API tokens work as before.

…fails the request - the API customer lookup skips schemes that are not registered (#888)

(cherry picked from commit 9b952f2)
@KrzysztofPajak
KrzysztofPajak merged commit 568ba95 into 2.4.x Oct 11, 2026
1 check passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/2.4.x-api-authentication-without-scheme branch October 11, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant