innmind / http-authentication
HTTP authentication
5.0.0
2025-08-24 19:55 UTC
Requires
- php: ~8.2
- innmind/foundation: ~1.9
Requires (Dev)
- innmind/black-box: ~6.5
- innmind/coding-standard: ~2.0
- innmind/static-analysis: ^1.2.1
This package is auto-updated.
Last update: 2025-08-24 19:56:05 UTC
README
Simple tool to authenticate a request.
Installation
composer require innmind/http-authentication
Usage
use Innmind\HttpAuthentication\ViaBasicAuthorization; use Innmind\Router\{ Router, Component, Collect, Handle, }; use Innmind\Http\{ ServerRequest, Response, }; use Innmind\Immutable\Attempt; function login(string $user, string $password): Attempt { // find the user } $router = Router::of( Component::of(ViaBasicAuthorization::of( static fn(string $user, string $password) => login($user, $password), )) ->map(Collect::of('user')) ->pipe(Handle::of( static fn(ServerRequest $request, mixed $user) => Attempt::result( Response::of( // build response ), ), )); ); $response = $router(/* an instance of Innmind\Http\Message\ServerRequest */)->unwrap();