title: Sabre Integration for CalDAV
body: <p>I'm working on a web-based scheduling application that needs to integrate iCloud Calendar into it. Unlike Google Calendar and Microsoft Outlook, I came to know that iCloud doesn't provide any APIs for integration. So, I came to know about Sabre CalDAV.</p>
  <p>But instead of progressing, I got stuck into its comprehensive documentation. Does anyone have proper documentation or could help me out with authenticating: Sabre\DAV\Auth\Backend\Apache(<a href="https://sabre.io/dav/caldav/" rel="nofollow noreferrer">https://sabre.io/dav/caldav/</a>) for Authentication.
  Also, I need to CalDAV plugin but it may require authentication first.</p>
  <p>Please find below as my server.php code:</p>
  <pre><code>&lt;?php
  
  use
      Sabre\DAV,
      Sabre\CalDAV,
      Sabre\DAVACL;
  
  $pdo = new \PDO('sqlite:data/db.sqlite');
  $pdo-&gt;setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
  
  //Mapping PHP errors to exceptions
  function exception_error_handler($errno, $errstr, $errfile, $errline ) {
      throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
  }
  set_error_handler(&quot;exception_error_handler&quot;);
  
  // Files we need
  require_once 'vendor/autoload.php';
  
  // Backends
  $authBackend = new DAV\Auth\Backend\PDO($pdo);
  $principalBackend = new DAVACL\PrincipalBackend\PDO($pdo);
  $calendarBackend = new CalDAV\Backend\PDO($pdo);
  
  // Directory tree
  $tree = array(
      new DAVACL\PrincipalCollection($principalBackend),
      new CalDAV\CalendarRoot($principalBackend, $calendarBackend)
  );  
  
  
  // The object tree needs in turn to be passed to the server class
  $server = new DAV\Server($tree);
  
  // You are highly encouraged to set your WebDAV server base url. Without it,
  // SabreDAV will guess, but the guess is not always correct. Putting the
  // server on the root of the domain will improve compatibility.
  $server-&gt;setBaseUri('/sabre/server.php');
  
  // Authentication plugin
  $authPlugin = new DAV\Auth\Plugin($authBackend,'SabreDAV');
  $server-&gt;addPlugin($authPlugin);
  
  // CalDAV plugin
  $caldavPlugin = new CalDAV\Plugin();
  $server-&gt;addPlugin($caldavPlugin);
  
  // CardDAV plugin
  $carddavPlugin = new CardDAV\Plugin();
  $server-&gt;addPlugin($carddavPlugin);
  
  // ACL plugin
  $aclPlugin = new DAVACL\Plugin();
  $server-&gt;addPlugin($aclPlugin);
  
  // Support for html frontend
  $browser = new DAV\Browser\Plugin();
  $server-&gt;addPlugin($browser);
  
  // And off we go!
  $server-&gt;exec();
  </code></pre>