monicahq / laravel-sabre Goto Github PK
View Code? Open in Web Editor NEWSabre.io DAV server adapter for Laravel
License: MIT License
Sabre.io DAV server adapter for Laravel
License: MIT License
Hi and thank you very much for this library.
I have multiple users and want to authenticate them against the laravel authentication.
This is my app/Providers/DAVServiceProvider.php
:
<?php
namespace App\Providers;
use App\Models\User;
use Sabre\HTTP\Sapi;
use Sabre\HTTP\Response;
use LaravelSabre\LaravelSabre;
use Sabre\DAVACL\PrincipalCollection;
use Illuminate\Support\ServiceProvider;
use LaravelSabre\Http\Auth\AuthBackend;
use Sabre\HTTP\Auth\Basic as BasicAuth;
use Sabre\DAV\Auth\Plugin as AuthPlugin;
use Sabre\DAV\FS\Directory as FsDirectory;
use Sabre\DAV\Locks\Plugin as LocksPlugin;
use Sabre\DAV\Browser\Plugin as BrowserPlugin;
use Sabre\DAVACL\PrincipalBackend\PDO as PrincipalBackend;
class DAVServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
LaravelSabre::auth(function () {
$request = Sapi::getRequest();
$response = new Response();
$auth = new BasicAuth('MyDrive WebDAV', $request, $response);
list($username, $password) = $auth->getCredentials();
\Log::debug($username . $password);
if ($username && $password) {
$user = User::whereUsername($username)
->wherePassword(md5($password))
->first();
if ($user && auth()->login($user)) {
return true;
}
}
$auth->requireLogin();
Sapi::sendResponse($response);
exit;
});
LaravelSabre::plugins(function () {
return $this->plugins();
});
LaravelSabre::nodes(function () {
return $this->nodes();
});
}
/**
* List of nodes for DAV Collection.
*/
private function nodes() : array
{
$rootDirectory = new FsDirectory(env('DATA_DIR'));
return [
$rootDirectory
];
}
/**
* List of Sabre plugins.
*/
private function plugins()
{
// Authentication backend
$authBackend = new AuthBackend();
yield new AuthPlugin($authBackend);
yield new BrowserPlugin(); // TODO: remove
/* yield new LocksPlugin(); */
}
}
As you can see, I search the user by username and password and get the correct eloquent model. Unfortunately at auth()->login($user)
I receive NULL.
Have you any idea?
Hello,
I can't authenticate the User if the Client is an Apple device (Built in Client) or an android device (DAVx App). At the Service file inside the LaravelSabre::auth function is always the error auth()->user() is null.
Where can i add the function to authorize Android and iOS Clients too. At the web frontend always Works good with the authorization.
Sorry for my Bad englisch.
I want to access dav server at subdomain, but it is not clear how to setup it
in config I have this
'domain' => 'dav',
'path' => '',
In DNS I setup A record dav.mydomain.com
pointing to my IP. But I cannot understand how to setup nginx config.
For example I have working config for baikal server. Here root is /var/www/baikal/html
. Which root should I use for laravel-sabre? Public folder of laravel doesn't work, because at dav.mydomain.com
, I just see laravel homepage, not sabre homepage
server {
server_name dav.lan baikal.lan dav.mydomain2.com baikal.mydomain2.com;
root /var/www/baikal/html;
index index.php;
rewrite ^/.well-known/caldav /dav.php redirect;
rewrite ^/.well-known/carddav /dav.php redirect;
charset utf-8;
location ~ /(\.ht|Core|Specific|config) {
deny all;
return 404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
File not found: ServerTest in 'root' ?
where can i find this folder or what is wrong?
For the moment CardDAV addressbooks are handled using the existing PDO connector Sabre\CardDAV\Backend\PDO
.
Having an example Laravel migration that creates the base tables that can easily be mapped to the Sabre ones could be useful.
Base tables can be found there https://github.com/sabre-io/dav/blob/master/examples/sql/mysql.addressbooks.sql
When I try to download large files (50MB or greater) I get following error:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 765055744 bytes) {"userId":14,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Allowed memory size of 134217728 bytes exhausted (tried to allocate 765055744 bytes) at /my-project/vendor/monicahq/laravel-sabre/src/Sabre/Server.php:87)
[stacktrace]
#0 /my-project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(148): Symfony\\Component\\Debug\\Exception\\FatalErrorException->__construct()
#1 /my-project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(134): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->fatalExceptionFromError()
#2 /my-project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(0): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleShutdown()
#3 /my-project/vendor/monicahq/laravel-sabre/src/Sabre/Server.php(87): stream_get_contents()
#4 /my-project/vendor/symfony/http-foundation/StreamedResponse.php(114): LaravelSabre\\Sabre\\Server->LaravelSabre\\Sabre\\{closure:/my-project/vendor/monicahq/laravel-sabre/src/Sabre/Server.php:85-91}()
#5 /my-project/vendor/symfony/http-foundation/Response.php(376): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /my-project/public/index.php(58): Symfony\\Component\\HttpFoundation\\StreamedResponse->send()
#7 /my-project/server.php(21): ()
#8 /my-project/server.php(0): {main}()
#9 {main}
"}
If I replace the lines vendor/monicahq/laravel-sabre/src/Sabre/Server.php:85-91
to:
if (ob_get_level()) ob_end_clean();
return response()->stream(function () use ($body) {
fpassthru($body);
}, $status, $headers);
it works perfectly.
So my qustions are:
Note: I want to support files up to 10GB, so just to increase the memory_limit, I think, isn't a good idea.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.