Authentication: use dynamic directory for each user

150 views
Skip to first unread message

Bailey Rud

unread,
Nov 29, 2014, 11:55:29 AM11/29/14
to sabredav...@googlegroups.com
Hello,

I currently develop an application with a webdav-server. Each user have their own home directory with their files. My webdav-server (based on SabreDAV) runs with authentication, but i don't know how to use the username of the authentication for the direcory. For example: when the user "test2" logins, the directory in webdav should be "/files/test2/".
Is this possible? When yes, how can i realize that in PHP?

Thank you for your help and sorry for my bad english (i'm from germany),
Bailey

paranerd

unread,
Dec 1, 2014, 5:38:50 AM12/1/14
to sabredav...@googlegroups.com
Currently having the same issue...

This is what I got:

$path = "";
$authBackend = new Sabre\DAV\Auth\Backend\BasicCallBack(function($userName, $password) {
if(login($userName, $password)) {
$path = $dataDir . $userName;
return true;
}
return false;
});

$root = new \Sabre\DAV\FS\Directory($path);
[..]

The problem is, that the "$root"-part gets called BEFORE the "$authBackend"-Part, so I get an error, that the $path can not be empty =/

Is there a "getUser()"-function or a way to get the functions to be called in the "right" order?

Thanks in advance.

Paranerd Smith

unread,
Dec 1, 2014, 12:17:49 PM12/1/14
to sabredav...@googlegroups.com
Found a possible solution:

use
    Sabre\HTTP\Sapi,
    Sabre\HTTP\Response,
    Sabre\HTTP\Auth;

$request = Sapi::getRequest();
$response = new Response();

$basicAuth = new Auth\Basic("Locked down area", $request, $response);
$basicAuth->requireLogin();
$user = $basicAuth->getCredentials();

$username = $user[0];
$password = $user[1];

Put that at the beginning of your script so you can set the proper path to each user directory.

--
You received this message because you are subscribed to a topic in the Google Groups "SabreDAV Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sabredav-discuss/3LovqGsfZ00/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sabredav-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sabredav-discuss/9393ef87-6f31-4615-9661-796de6d08977%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evert Pot

unread,
Dec 1, 2014, 12:22:56 PM12/1/14
to sabredav...@googlegroups.com
Hi guys,

That question was asked and answered a few times before:

https://groups.google.com/forum/#!topic/sabredav-discuss/MjJ0lWdaFvc
https://groups.google.com/forum/#!searchin/sabredav-discuss/getCurrentUSer/sabredav-discuss/k9RvApCtG8k/4zuIa8YJJ1MJ

This issue seems to be common enough to add a FAQ entry for though, so I will try to make some time today to take those discussions and turn them into a good documentation page.

Evert


On Monday, December 1, 2014 12:17:49 PM UTC-5, paranerd wrote:
Found a possible solution:

use
    Sabre\HTTP\Sapi,
    Sabre\HTTP\Response,
    Sabre\HTTP\Auth;

$request = Sapi::getRequest();
$response = new Response();

$basicAuth = new Auth\Basic("Locked down area", $request, $response);
$basicAuth->requireLogin();
$user = $basicAuth->getCredentials();

$username = $user[0];
$password = $user[1];

Put that at the beginning of your script so you can set the proper path to each user directory.
2014-12-01 11:38 GMT+01:00 paranerd <paranerd.development@gmail.com>:
Currently having the same issue...

This is what I got:

$path = "";
$authBackend = new Sabre\DAV\Auth\Backend\BasicCallBack(function($userName, $password) {
if(login($userName, $password)) {
$path = $dataDir . $userName;
return true;
}
return false;
});

$root = new \Sabre\DAV\FS\Directory($path);
[..]

The problem is, that the "$root"-part gets called BEFORE the "$authBackend"-Part, so I get an error, that the $path can not be empty =/

Is there a "getUser()"-function or a way to get the functions to be called in the "right" order?

Thanks in advance.

Am Samstag, 29. November 2014 17:55:29 UTC+1 schrieb Bailey Rud:
Hello,

I currently develop an application with a webdav-server. Each user have their own home directory with their files. My webdav-server (based on SabreDAV) runs with authentication, but i don't know how to use the username of the authentication for the direcory. For example: when the user "test2" logins, the directory in webdav should be "/files/test2/".
Is this possible? When yes, how can i realize that in PHP?

Thank you for your help and sorry for my bad english (i'm from germany),
Bailey

--
You received this message because you are subscribed to a topic in the Google Groups "SabreDAV Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sabredav-discuss/3LovqGsfZ00/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sabredav-discuss+unsubscribe@googlegroups.com.

Evert Pot

unread,
Dec 1, 2014, 3:49:33 PM12/1/14
to sabredav...@googlegroups.com
Hi everyone,

I wrote new docs for this. It takes the previous threads and goes into a lot more detail on how to solve this issue.

It's possible that it's vague in some areas, so I would also love to hear if there are bits you don't understand/I didn't explain well enough.

Evert

Evert Pot

unread,
Dec 1, 2014, 3:49:53 PM12/1/14
to sabredav...@googlegroups.com


On Monday, December 1, 2014 3:49:33 PM UTC-5, Evert Pot wrote:
Hi everyone,

I wrote new docs for this. It takes the previous threads and goes into a lot more detail on how to solve this issue.

It's possible that it's vague in some areas, so I would also love to hear if there are bits you don't understand/I didn't explain well enough.

forgot to include the actual link:

http://sabre.io/dav/per-user-directories/

Evert
Reply all
Reply to author
Forward
0 new messages