HTTP Authentication Management for PHP
Library to manage HTTP authentication with PHP.
You can install this package quick and easy with Composer.
Require the package via Composer:
$ composer require intervention/httpauth
The workflow is easy. Just create an authentication instance in the first step and secure your resource with a second step.
To create HTTP authentication instances you can choose between different methods.
use Intervention\HttpAuth\Authenticator; $auth = Authenticator::basic('Secured Realm'); $auth->withUsername('admin'); $auth->withPassword('secret');
use Intervention\HttpAuth\Authenticator; // create basic auth by array $auth = Authenticator::make([ 'type' => 'basic', 'realm' => 'Secure Resource', 'username' => 'admin', 'password' => 'secret', ]);
use Intervention\HttpAuth\Authenticator; $auth = new Authenticator( 'basic', 'Secure Resource', 'admin', 'secret' ); // alternatively use methods to set properties $auth = new Authenticator(); $auth->withType('digest'); $auth->withRealm('Secure'); $auth->withCredentials('admin', 'secret');
After you created a HTTP authentication instance, you have to call
secure() to secure the resource. This results in a 401 HTTP response and the browser asking for credentials.
If you are using Apache and running php with fast-cgi, check setting headers: https://support.deskpro.com/en/kb/articles/missing-authorization-headers-with-apache
Intervention HttpAuth Class is licensed under the MIT License.