Intervention HttpAuth
HTTP Authentication Management
309k Downloads / Month
Open Source MIT License
309k Downloads / Month
Open Source MIT License
Intervention HttpAuth is a PHP library for authenticating resources using HTTP Basic or Digest authentication. Learn how to install and configure the package correctly.
The package provides an API that makes these steps as simple as possible.
The workflow is divided into two steps. In the first, an instance of the
Authenticator::class class is created and you decide which type of authentication
to use. In the second step, the resource is secured with a
single call.
First, the library must be installed in the application. It can then be integrated as follows.
To create authenticator instances you can choose between basic & digest auth. Simply use the static helper methods described below or learn how to instantiate the authenticator in other ways.
use Intervention\HttpAuth\Authenticator; // create http basic auth $auth = Authenticator::basic( 'myUsername', 'myPassword', );
use Intervention\HttpAuth\Authenticator; // create http digest auth $auth = Authenticator::digest( 'myUsername', 'myPassword', );
After you create an HTTP authentication instance, you need to call secure()
to secure the resource. This results in a 401 HTTP response and prompts the browser
to ask for credentials.
$auth->secure();
A string can optionally be passed to the method. This is displayed if authentication fails. Output from template engines can also be used here.
$auth->secure('Sorry, you can not access this resource!');
Read more on how to install or use the package.