Skip to content

Innmind/HttpAuthentication

Repository files navigation

Http authentication

Build Status codecov Type Coverage

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\ServerRequest */)->unwrap();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages