]> git.mxchange.org Git - friendica-addons.git/blob - dav/dav_friendica_auth.inc.php
Libertree: Posting works again (new "source" field)
[friendica-addons.git] / dav / dav_friendica_auth.inc.php
1 <?php
2
3 class Sabre_DAV_Auth_Backend_Friendica extends Sabre_DAV_Auth_Backend_AbstractBasic {
4
5     public function __construct() {
6     }
7
8
9     public function getUsers() {
10         return array($this->currentUser);
11     }
12     
13     public function getCurrentUser() {
14         return $this->currentUser;
15     }
16
17         /**
18          * Authenticates the user based on the current request.
19          *
20          * If authentication is successful, true must be returned.
21          * If authentication fails, an exception must be thrown.
22          *
23          * @param Sabre_DAV_Server $server
24          * @param string $realm
25          * @throws Sabre_DAV_Exception_NotAuthenticated
26          * @return bool
27          */
28         public function authenticate(Sabre_DAV_Server $server, $realm) {
29
30                 $auth = new Sabre_HTTP_BasicAuth();
31                 $auth->setHTTPRequest($server->httpRequest);
32                 $auth->setHTTPResponse($server->httpResponse);
33                 $auth->setRealm($realm);
34                 $userpass = $auth->getUserPass();
35                 if (!$userpass) {
36                         $auth->requireLogin();
37                         throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found');
38                 }
39
40                 // Authenticates the user
41                 if (!$this->validateUserPass($userpass[0],$userpass[1])) {
42                         $auth->requireLogin();
43                         throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match');
44                 }
45                 $this->currentUser = strtolower($userpass[0]);
46                 return true;
47         }
48
49
50         protected function validateUserPass($username, $password) {
51
52                 $user = array(
53                     'uri' => "/" . 'principals/users/' . strtolower($username),
54                 );
55                 return $user;
56     }
57     
58 }