2017 © Pedro Peláez
 

library http-authentication

Middleware to implement Basic and Digest Http authentication

image

middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  • Thursday, January 25, 2018
  • by oscarotero
  • Repository
  • 3 Watchers
  • 14 Stars
  • 3,014 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

middlewares/http-authentication

Latest Version on Packagist ![Software License][ico-license] Testing ![Total Downloads][ico-downloads], (*1)

Middleware to implement RFC 2617 Http Authentication. Contains the following components:, (*2)

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/http-authentication., (*3)

composer require middlewares/http-authentication

BasicAuthentication

The Basic access authentication is the simplest technique., (*4)

You have to provide an Array or ArrayAccess with the usernames and passwords of all available users. The keys are the usernames and the values the passwords., (*5)

Dispatcher::run([
    new Middlewares\BasicAuthentication([
        'username1' => 'password1',
        'username2' => 'password2'
    ])
]);

Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument, that will be used to create the error responses (401). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically., (*6)

$responseFactory = new MyOwnResponseFactory();

$route = new Middlewares\BasicAuthentication($users, $responseFactory);

realm

The realm value. By default is "Login"., (*7)

attribute

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

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

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

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

verifyHash

This option verifies the password using password_verify. Useful if you don't want to provide the passwords in plain text., (*9)

$users = [
    'username' => password_hash('secret-password', PASSWORD_DEFAULT);
]

Dispatcher::run([
    (new Middlewares\BasicAuthentication($users))
        ->attribute('username')
        ->verifyHash(),

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

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

DigestAuthentication

The Digest access authentication is more secure than basic., (*10)

The constructor signature is the same than BasicAuthentication:, (*11)

$users = [
    'username1' => 'password1',
    'username2' => 'password2'
];
$responseFactory = new MyOwnResponseFactory();

Dispatcher::run([
    new Middlewares\DigestAuthentication($users, $responseFactory)
]);

realm

The realm value. By default is "Login"., (*12)

attribute

The attribute name used to save the username of the user. If it's not defined, it wont be saved., (*13)

nonce

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


Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details., (*15)

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

The Versions

25/01 2018

dev-master

9999999-dev https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest

25/01 2018

v1.0.0

1.0.0.0 https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest

13/11 2017

v0.5.0

0.5.0.0 https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest

21/09 2017

v0.4.0

0.4.0.0 https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest

26/12 2016

v0.3.0

0.3.0.0 https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest

23/11 2016

v0.2.0

0.2.0.0 https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest

02/10 2016

v0.1.0

0.1.0.0 https://github.com/middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 authentication server http basic psr-15 digest