Skip to content
PSR-15 middleware to implement Basic and Digest Http authentication
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Allow to definte the factories in the constructor Oct 12, 2018
tests
.editorconfig first commit Oct 2, 2016
.gitattributes first commit Oct 2, 2016
.gitignore
.php_cs psr-17 Aug 2, 2018
.travis.yml Added php 7.2 to travis Jan 14, 2018
CHANGELOG.md Allow to definte the factories in the constructor Oct 12, 2018
CONTRIBUTING.md Code coverage tests Jan 13, 2018
LICENSE
README.md Updated docs Aug 4, 2018
composer.json fixed phpstan Oct 11, 2018
phpcs.xml.dist Improved configuration Sep 2, 2017
phpunit.xml.dist Improved configuration Sep 2, 2017

README.md

middlewares/http-authentication

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Middleware to implement RFC 2617 Http Authentication. Contains the following components:

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/http-authentication.

composer require middlewares/http-authentication

BasicAuthentication

The Basic access authentication is the simplest technique.

__construct(array|ArrayAccess $users)

Array or ArrayAccess with the usernames and passwords of all available users. The keys are the usernames and the values the passwords.

realm(string $realm)

The realm value. By default is "Login".

attribute(string $attribute)

The attribute name used to save the username of the user. If it's not defined, it wont be saved. Example:

$dispatcher = new Dispatcher([
    (new Middlewares\BasicAuthentication([
        'username1' => 'password1',
        'username2' => 'password2'
    ]))->attribute('username'),

    function ($request) {
        $username = $request->getAttribute('username');

        return new Response('Hello '.$username);
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());

responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)

A PSR-17 factory to create 401 responses.

DigestAuthentication

The Digest access authentication is more secure than basic.

__construct(array|ArrayAccess $users)

Array or ArrayAccess with the usernames and passwords of all available users. The keys are the usernames and the values the passwords.

realm(string $realm)

The realm value. By default is "Login".

attribute(string $attribute)

The attribute name used to save the username of the user. If it's not defined, it wont be saved. Example:

nonce(string $nonce)

To configure the nonce value. If its not defined, it's generated with uniqid

$dispatcher = new Dispatcher([
    (new Middlewares\DigestAuthentication([
        'username1' => 'password1',
        'username2' => 'password2'
    ]))->attribute('username'),

    function ($request) {
        $username = $request->getAttribute('username');

        return new Response('Hello '.$username);
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());

responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)

A PSR-17 factory to create 401 responses.


Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

You can’t perform that action at this time.