zimbra-api / soap-api

Zimbra SOAP client in PHP language
BSD 3-Clause "New" or "Revised" License
63 stars 49 forks source link

Error when using $api->authPre() #10

Closed pierre-charpentier closed 8 years ago

pierre-charpentier commented 8 years ago

Issue

Encountered an error when using authPre():

$account = new AccountSelector(AccountBy::NAME(), $mail);
$api = MailFactory::instance('https://HOSTNAME/service/soap');
$api->authPre($account, ZIMBRA_PREAUTH_KEY);

That is what I get:

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ServerException' with message 'Server error response [url] https://HOSTNAME/service/soap [status code] 500 [reason phrase] Server Error' in    /PROJECT_PATH/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace:

#0 /PROJECT_PATH/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response))

#1 /PROJECT_PATH/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete')

#2 /PROJECT_PATH/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent))

#3 /PROJECT_PATH/vendor/guzzlehtt in /PROJECT_PATH/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 89

Possible solution

After some investigation around authPre(), I saw that the expires parameter is not set at all when using the authPre() method. You end up having a concatened string looking like hisjohn.doe@domain.com|name||1135280708088.

Creating my own PreAuth object specifying the expires parameter, and using auth(), solved my issue and allowed me the authenticate successfully.

$preAuth = new PreAuth(time() * 1000, null, 0);
$preAuth->computeValue($account, ZIMBRA_PREAUTH_KEY);
$api = MailFactory::instance('https://HOSTNAME/service/soap');
$api->auth($account, null, $preAuth);

I am still not sure if this is the right way to solve the problem, but it works and I am able to retrieve unread messages like I wanted.

Should the expires value be set to 0 by default?

anardil commented 8 years ago

Hi @Qayou,

I'm new with this library and I found nowhere some documentations or example to use it. I'm trying to use the method "createAppointment" but for me the params are chinesee for me. Did you try something with this method ?

Thank you.

pierre-charpentier commented 8 years ago

Hi @anardil,

I did not try anything with this method I am sorry. But look at the Mail/Request/CreateAppointment class, you can see it is empty. I think this method is not implmented in this API for now.

You should ask @nguyennv or open an issue/suggestion.

Cheers!

anardil commented 8 years ago

Hello @Qayou,

Thanks for your reply. In fact this method is here => zimbra-api/src/Zimbra/Mail/Base.php. line 558

I have already opened an issue for that.

This API is very large and complex, it's a shame to have no documentation :(.

pierre-charpentier commented 8 years ago

@anardil if you check the method, you will see it uses the Mail/Request/CreateAppointment class. And this class is empty so I would not expect it to work without some work.

anardil commented 8 years ago

@Qayou

For me this class is ok. "CreateAppointment" extends the class "CalItemRequestBase". It's empty because this class doesn't need to have more properties or redefine methods in parent class.

I hope @nguyennv will reply me :)

anardil commented 8 years ago

Hello @Qayou,

nguyennv has given me the solution, you can find it here -> https://github.com/zimbra-api/zimbra-api/issues/11#issuecomment-245861141

Now I'm interested by the preAuth method. In your solution you used the constant "ZIMBRA_PREAUTH_KEY", how did you get this key?

Thank you.

pierre-charpentier commented 8 years ago

Hi @anardil,

The Zimbra documentation is well done for that. See PreAuth.

To sum it up, on your Zimbra server you can generate a preAuth key using

zmprov generateDomainPreAuthKey YOUR_DOMAIN

or see a key that is already generated using

zmprov gd YOUR_DOMAIN zimbraPreAuthKey

I hope it helps!

anardil commented 8 years ago

Thank you, I'm going to try.

anardil commented 8 years ago

It works like a charm. Thank you.