musonic/sabre-accounts

Plugin for SabreDAV library

dev-master 2013-04-25 13:00 UTC

This package is not auto-updated.

Last update: 2024-04-22 09:27:52 UTC


README

Accounts plugin for SabreDAV a WebDAV framework for PHP. This plugin allows for the creation of users and principals remotely via HTTP request. If you're not sure what the difference is then take a look here: http://tools.ietf.org/html/rfc3744#section-2

Requirements

This requires SabreDAV version 1.8 or later.

The assumption is that you have setup a users table in your database as outlined here: https://code.google.com/p/sabredav/wiki/CalDAV#Database_setup

Installation

To install this plugin, make sure you have SabreDAV installed using the composer installation instructions. To add this plugin, just add the following line to your composer file in the requires section:

"musonic/sabre-accounts" : "dev-master"

After adding that, you can just run composer update to complete the installation.

  1. Manually add a 'super_user' to your users table. This user is the only user authorized to add new users to the database.

  2. Update your server.php file (or whatever you have named it)

$accountsBackend = new \SabreAccounts\DAV\Accounts\Backend\PDO($pdo);
$account = new \SabreAccounts\DAV\Accounts\Plugin($accountsBackend);
$account->set_superuser('your_super_user');
$server->addPlugin($account);   

Usage

Creating a user

The plugin works by sending an HTTP POST request to the server with a custom header and a very simple JSON body. The request MUST include the following:

  1. A Content-Type header of application/json
  2. A request body in JSON format that simply contains the username of user you want to add along with a password in digesta1 format. eg.
$body = json_encode(array('username'=>$username, 'digesta1'=>$password));

Creating principals

  1. Update your server.php file to use the correct principals backend
$principalsBackend = new \SabreAccounts\DAVACL\PrincipalBackend\MusonicPDO(
    $pdo, 
    $principalsTable,
    $groupMembersTableName      
);
  1. Update your document tree so that the principals collection is an instance of SabreAccounts\CalDAV\Principal\MusonicCollection
  2. To create a new principal you need to make a MKCOL request. The body of the request should be something like this:
    <?xml version="1.0" encoding="utf-8" ?>
            <D:mkcol xmlns:D="DAV:" xmlns:S="http://sabredav.org/ns">
                <D:set>
                    <D:prop>
                        <D:resourcetype>
                            <D:collection/>
                            <D:principal/>
                        </D:resourcetype>
                        <D:displayname>Joe Bloggs</D:displayname>
                        <S:email-address>joebloggs@example.com</S:email-address>
                    </D:prop>
                </D:set>
            </D:mkcol>

Remember to make the request to the principal you are creating. ie /principals/newprincipal, not just /principals/