Digest
HTTP Digest Authentication handler.
Use this class for easy http digest authentication. Instructions:
- Create the object
- Call the setRealm() method with the realm you plan to use
- Call the init method function.
- Call the getUserName() function. This function may return null if no authentication information was supplied. Based on the username you should check your internal database for either the associated password, or the so-called A1 hash of the digest.
- Call either validatePassword() or validateA1(). This will return true or false.
-
To make sure an authentication prompt is displayed, call the requireLogin() method.
-
Full name:
\Sabre\HTTP\Auth\Digest
- Parent class:
\Sabre\HTTP\Auth\AbstractAuth
Constants
Constant | Visibility | Type | Value |
---|---|---|---|
QOP_AUTH |
public | 1 | |
QOP_AUTHINT |
public | 2 |
Properties
nonce
opaque
digestParts
A1
qop
Methods
__construct
Initializes the object.
public __construct(string $realm, \Sabre\HTTP\RequestInterface $request, \Sabre\HTTP\ResponseInterface $response): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$realm |
string | |
$request |
\Sabre\HTTP\RequestInterface | |
$response |
\Sabre\HTTP\ResponseInterface |
init
Gathers all information from the headers.
This method needs to be called prior to anything else.
setQOP
Sets the quality of protection value.
Possible values are: Sabre\HTTP\DigestAuth::QOP_AUTH Sabre\HTTP\DigestAuth::QOP_AUTHINT
Multiple values can be specified using logical OR.
QOP_AUTHINT ensures integrity of the request body, but this is not supported by most HTTP clients. QOP_AUTHINT also requires the entire request body to be md5'ed, which can put strains on CPU and memory.
Parameters:
Parameter | Type | Description |
---|---|---|
$qop |
int |
validateA1
Validates the user.
The A1 parameter should be md5($username . ':' . $realm . ':' . $password);
Parameters:
Parameter | Type | Description |
---|---|---|
$A1 |
string |
validatePassword
Validates authentication through a password. The actual password must be provided here.
It is strongly recommended not store the password in plain-text and use validateA1 instead.
Parameters:
Parameter | Type | Description |
---|---|---|
$password |
string |
getUsername
Returns the username for the request.
Returns null if there were none.
validate
Validates the digest challenge.
requireLogin
Returns an HTTP 401 header, forcing login.
This should be called when username and password are incorrect, or not supplied at all
getDigest
This method returns the full digest string.
It should be compatible with mod_php format and other webservers.
If the header could not be found, null will be returned
parseDigest
Parses the different pieces of the digest string into an array.
This method returns false if an incomplete digest was supplied
Parameters:
Parameter | Type | Description |
---|---|---|
$digest |
string |
Inherited methods
__construct
Creates the object.
public __construct(string $realm, \Sabre\HTTP\RequestInterface $request, \Sabre\HTTP\ResponseInterface $response): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$realm |
string | |
$request |
\Sabre\HTTP\RequestInterface | |
$response |
\Sabre\HTTP\ResponseInterface |
requireLogin
This method sends the needed HTTP header and status code (401) to force the user to login.
- This method is abstract.
getRealm
Returns the HTTP realm.
Automatically generated on 2025-03-18