Skip to content

HttpBasicAuthenticator

Decodes an Authorization: Basic header and verifies it against a UserProviderInterface/PasswordHasherInterface pair.

Stateless: identity is re-derived from the header every request.

packages/ratelimit is a soft dependency: pass a LoginThrottle to enable brute-force throttling, or omit it to skip it. It matters more here than on FormLoginAuthenticator — a Basic credential rides on every request with no form to fetch, no token to obtain and no session to establish first, so an unthrottled Basic surface is the cheapest password-guessing target an application can expose.

final class HttpBasicAuthenticator implements AuthenticatorInterface

ImplementsAuthenticatorInterface
Since1.0.0
SourceAuthenticator/HttpBasicAuthenticator.php

public function __construct(UserProviderInterface $userProvider, PasswordHasherInterface $passwordHasher, ?LoginThrottle $throttle = null): mixed

When given, failed attempts are throttled per identifier and per client (see packages/ratelimit).

ParameterTypeDescription
$userProviderUserProviderInterfaceResolves the decoded username to an identity.
$passwordHasherPasswordHasherInterfaceVerifies the decoded password against the identity’s stored hash.
$throttle?LoginThrottleWhen given, failed attempts are throttled per identifier and per client (see packages/ratelimit).

Returns mixed

MethodDescription
authenticate(ServerRequestInterface $request): Passport
onFailure(AuthenticationException $exception): null
supports(ServerRequestInterface $request): bool

public function authenticate(ServerRequestInterface $request): Passport

The incoming request.

ParameterTypeDescription
$requestServerRequestInterfaceThe incoming request.

Returns Passport — The resolved identity, stateless (re-derived from the header every request).

ThrowsWhen
AuthenticationExceptionIf the header is malformed, credentials are missing, the user is unknown, the password is wrong, or the throttle is exhausted.

public function onFailure(AuthenticationException $exception): null

The exception thrown by authenticate().

ParameterTypeDescription
$exceptionAuthenticationExceptionThe exception thrown by authenticate().

Returns null — Always null: defers to the firewall’s HttpChallengeEntryPoint.

public function supports(ServerRequestInterface $request): bool

The incoming request.

ParameterTypeDescription
$requestServerRequestInterfaceThe incoming request.

Returns bool — True if $request carries an Authorization: Basic header, otherwise false.