]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/HTTP/BasicAuth.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / HTTP / BasicAuth.php
1 <?php
2
3 /**
4  * HTTP Basic Authentication handler
5  *
6  * Use this class for easy http authentication setup
7  *
8  * @package Sabre
9  * @subpackage HTTP
10  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11  * @author Evert Pot (http://www.rooftopsolutions.nl/)
12  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
13  */
14 class Sabre_HTTP_BasicAuth extends Sabre_HTTP_AbstractAuth {
15
16     /**
17      * Returns the supplied username and password.
18      *
19      * The returned array has two values:
20      *   * 0 - username
21      *   * 1 - password
22      *
23      * If nothing was supplied, 'false' will be returned
24      *
25      * @return mixed
26      */
27     public function getUserPass() {
28
29         // Apache and mod_php
30         if (($user = $this->httpRequest->getRawServerValue('PHP_AUTH_USER')) && ($pass = $this->httpRequest->getRawServerValue('PHP_AUTH_PW'))) {
31
32             return array($user,$pass);
33
34         }
35
36         // Most other webservers
37         $auth = $this->httpRequest->getHeader('Authorization');
38
39         // Apache could prefix environment variables with REDIRECT_ when urls
40         // are passed through mod_rewrite
41         if (!$auth) {
42             $auth = $this->httpRequest->getRawServerValue('REDIRECT_HTTP_AUTHORIZATION');
43         }
44
45         if (!$auth) return false;
46
47         if (strpos(strtolower($auth),'basic')!==0) return false;
48
49         return explode(':', base64_decode(substr($auth, 6)),2);
50
51     }
52
53     /**
54      * Returns an HTTP 401 header, forcing login
55      *
56      * This should be called when username and password are incorrect, or not supplied at all
57      *
58      * @return void
59      */
60     public function requireLogin() {
61
62         $this->httpResponse->setHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"');
63         $this->httpResponse->sendStatus(401);
64
65     }
66
67 }