zimbra-api php delegateAuth

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
Advanced member
Advanced member
Posts: 94
Joined: Fri Sep 12, 2014 10:12 pm

zimbra-api php delegateAuth

Postby undertoe » Fri Jan 26, 2018 5:06 pm

Trying to build a web app to create an appoint as any user.

The following works great in a single user scenario if i have the users password. However I would like to auth as admin and then create the appointment as if the user I pick created it. I was reading about delegateAuth but can't find any examples on how to successfully implement. Can someone help or post an example

Code: Select all

use Zimbra\Enum\AccountBy;
use Zimbra\Enum\AddressType;
use Zimbra\Enum\AlarmAction;
use Zimbra\Enum\FreeBusyStatus;
use Zimbra\Enum\InviteStatus;
use Zimbra\Enum\InviteClass;
use Zimbra\Enum\ParticipationStatus;
use Zimbra\Enum\Transparency;

use Zimbra\Mail\MailFactory;
use Zimbra\Mail\Struct\AlarmInfo;
use Zimbra\Mail\Struct\AlarmTriggerInfo;
use Zimbra\Mail\Struct\CalendarAttendee;
use Zimbra\Mail\Struct\CalOrganizer;
use Zimbra\Mail\Struct\DtTimeInfo;
use Zimbra\Mail\Struct\DurationInfo;
use Zimbra\Mail\Struct\EmailAddrInfo;
use Zimbra\Mail\Struct\InvitationInfo;
use Zimbra\Mail\Struct\InviteComponent;
use Zimbra\Mail\Struct\MimePartInfo;
use Zimbra\Mail\Struct\Msg;

use Zimbra\Struct\AccountSelector;

$api = MailFactory::instance('https://zimbraserver/service/soap');
try {
    $account = new AccountSelector(AccountBy::NAME(), 'test@mailserver.com');
    $api->auth($account, 'xxxx');

    $trigger = new AlarmTriggerInfo();
    $trigger->setRelative(new DurationInfo(true, null, null, null, 5, null, 'START'));
    $alarm = new AlarmInfo(AlarmAction::DISPLAY(), $trigger);

    $comp = new InviteComponent();
    $comp->setName('Meet celebrities for free')
        ->setLocation('My home')
        ->addAttendee(new CalendarAttendee('test@mailserver.com', null, 'User1'))
        ->setDtStart(new DtTimeInfo('20180130T160000', 'America/New_York'))
        ->setDtEnd(new DtTimeInfo('20180130T170000', 'America/New_York'))

    $inv = new InvitationInfo();

    $mp = new MimePartInfo(null, 'multipart/alternative');
    $mp->addMimePart(new MimePartInfo(null, 'text/plain', 'Meet celebrities for free'));

    $msg = new Msg();
    $msg->setSubject('Meet celebrities for free')
        ->addEmail(new EmailAddrInfo('test@mailserver.com', AddressType::TO(), 'User1'))
    $result = $api->createAppointment($msg);
catch(Exception $ex) {
    $client = $api->getClient();
    echo $client->lastResponse();

Posts: 4
Joined: Fri Jan 26, 2018 4:45 pm

Re: zimbra-api php delegateAuth

Postby bnystrom » Wed Jan 31, 2018 4:36 pm

To get a delegate auth token, you need to make a SOAP request with a <DelegateAuthRequest/> with an account name you choose. In this request you must specify an admin authentication token in the SOAP Envelope header.

I'm not sure how the syntax would work using the zimbra-api library, but I'm sure you must call the `auth` function with the admin credentials then some delegateAuth function with the user credentials. Then make the call on behalf of the user. I hope this helps. Good luck :)
Advanced member
Advanced member
Posts: 94
Joined: Fri Sep 12, 2014 10:12 pm

Re: zimbra-api php delegateAuth

Postby undertoe » Wed Jan 31, 2018 6:27 pm

Sorry forgot to update it. i ended up figuring it out. Here is the solution if anyone else needs it

You need to generate a preauth token on your zimbra server

Code: Select all

$account = new AccountSelector(AccountBy::NAME(), 'test@domain.com');
$preAuth = new PreAuth(time() * 1000, null, 0);
$preAuth->computeValue($account, INSERT_GENERATE_PREAUTH_TOKEN_HERE );
$api = MailFactory::instance('https://domain.com/service/soap');
$result = $api->auth($account, null, $preAuth);

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 3 guests