ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP\Auth\Basic Class Reference

HTTP Basic authentication utility. More...

+ Inheritance diagram for Sabre\HTTP\Auth\Basic:
+ Collaboration diagram for Sabre\HTTP\Auth\Basic:

Public Member Functions

 getCredentials ()
 This method returns a numeric array with a username and password as the only elements. More...
 
 requireLogin ()
 This method sends the needed HTTP header and statuscode (401) to force the user to login. More...
 
- Public Member Functions inherited from Sabre\HTTP\Auth\AbstractAuth
 __construct ($realm='SabreTooth', RequestInterface $request, ResponseInterface $response)
 Creates the object. More...
 
 requireLogin ()
 This method sends the needed HTTP header and statuscode (401) to force the user to login. More...
 
 getRealm ()
 Returns the HTTP realm. More...
 

Additional Inherited Members

- Protected Attributes inherited from Sabre\HTTP\Auth\AbstractAuth
 $realm
 
 $request
 
 $response
 

Detailed Description

HTTP Basic authentication utility.

This class helps you setup basic auth. The process is fairly simple:

  1. Instantiate the class.
  2. Call getCredentials (this will return null or a user/pass pair)
  3. If you didn't get valid credentials, call 'requireLogin'
Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 18 of file Basic.php.

Member Function Documentation

◆ getCredentials()

Sabre\HTTP\Auth\Basic::getCredentials ( )

This method returns a numeric array with a username and password as the only elements.

If no credentials were found, this method returns null.

Returns
null|array

Definition at line 28 of file Basic.php.

References $auth.

28  {
29 
30  $auth = $this->request->getHeader('Authorization');
31 
32  if (!$auth) {
33  return null;
34  }
35 
36  if (strtolower(substr($auth, 0, 6)) !== 'basic ') {
37  return null;
38  }
39 
40  $credentials = explode(':', base64_decode(substr($auth, 6)), 2);
41 
42  if (2 !== count($credentials)) {
43  return null;
44  }
45 
46  return $credentials;
47 
48  }
$auth
Definition: fileserver.php:48

◆ requireLogin()

Sabre\HTTP\Auth\Basic::requireLogin ( )

This method sends the needed HTTP header and statuscode (401) to force the user to login.

Returns
void

Definition at line 56 of file Basic.php.

56  {
57 
58  $this->response->addHeader('WWW-Authenticate', 'Basic realm="' . $this->realm . '", charset="UTF-8"');
59  $this->response->setStatus(401);
60 
61  }

The documentation for this class was generated from the following file: