Move WebDAVAuth to User_External

This commit is contained in:
Thomas Müller
2015-09-21 17:21:53 +02:00
parent 7cd539aa73
commit 91417ffddf
2 changed files with 71 additions and 0 deletions

View File

@@ -107,3 +107,23 @@ Add the following to your `config.php`:
### Dependencies
The `smbclient` executable needs to be installed and accessible within `$PATH`.
WebDAV
------
Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other web server to authenticate. It should return http 200 for right credentials and http 401 for wrong ones.
Attention: This app is not compatible with the LDAP user and group backend. This app is not the WebDAV interface of ownCloud, if you don't understand what it does then do not enable it.
### Configuration
The only supported parameter is the URL of the web server.
Add the following to your `config.php`:
'user_backends' => array(
array(
'class' => '\OCA\User_External\WebDAVAuth',
'arguments' => array('https://example.com/webdav'),
),
),

51
lib/webdavauth.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
/**
* Copyright (c) 2015 Thomas Müller <thomas.mueller@tmit.eu>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\user_external;
class WebDavAuth extends Base {
private $webDavAuthUrl;
public function __construct($webDavAuthUrl) {
parent::__construct($webDavAuthUrl);
$this->$webDavAuthUrl =$webDavAuthUrl;
}
/**
* Check if the password is correct without logging in the user
*
* @param string $uid The username
* @param string $password The password
*
* @return true/false
*/
public function checkPassword($uid, $password) {
$arr = explode('://', $this->webDavAuthUrl, 2);
if( ! isset($arr) OR count($arr) !== 2) {
\OCP\Util::writeLog('OC_USER_WEBDAVAUTH', 'Invalid Url: "'.$this->webDavAuthUrl.'" ', 3);
return false;
}
list($protocol, $path) = $arr;
$url= $protocol.'://'.urlencode($uid).':'.urlencode($password).'@'.$path;
$headers = get_headers($url);
if($headers==false) {
\OCP\Util::writeLog('OC_USER_WEBDAVAUTH', 'Not possible to connect to WebDAV Url: "'.$protocol.'://'.$path.'" ', 3);
return false;
}
$returnCode= substr($headers[0], 9, 3);
if(substr($returnCode, 0, 1) === '2') {
$this->storeUser($uid);
return $uid;
} else {
return false;
}
}
}