Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-07-2011, 10:56 AM
Starter Member
 
Posts: 2
Default [SOLVED] Rest Get Calendar Authentication

I am new to Zimbra and I am trying to get calendar events fed from Zimbra into our database using a PL SQL script from Oracle. I am trying to use the REST API Get Calendar Method. I can establish the connection through the URL directly from IE, but it prompts me. I am trying to get around the prompt, so that I can establish the connection without being prompted. Does anyone have a suggestion on how to handle this?

Here is the code I am trying to execute:

************************************************** ********

SET SERVEROUTPUT ON;
declare
http_response varchar2(4000);

BEGIN
DBMS_OUTPUT.ENABLE(1000000);


http_response := utl_http.request('http://cherry.serv15.eiu.edu/service/home/mldrake@testmail.eiu.edu/Calendar?fmt=xml');



DBMS_OUTPUT.PUT_LINE( http_response);

END;
.
RUN

************************************************** ********

Any help would be greatly appreciated! Thanks so much.
Reply With Quote
  #2 (permalink)  
Old 03-09-2011, 12:19 PM
Starter Member
 
Posts: 2
Default Zimbra authentication SOLVED for REST Get Calendar

We have figured out how to do this.

here is the code for PL SQL in Oracle:
************************************************** ********
SET SERVEROUTPUT ON;
declare
l_key varchar2(2000) := 'af26789543ac'; --This is whatever your zimbraPreAuth key value is from the Zimbra server l_current_timestamp number;
l_preauth_values varchar2(2000);
l_mac raw(2000);
http_response varchar2(4000);

BEGIN
DBMS_OUTPUT.ENABLE(1000000);

--This calls the get_date_millis function and returns the date back in milliseconds
l_current_timestamp := get_date_millis(sysdate);

--This builds the string that is required to generate the hmac
l_preauth_values := 'mbwalton@test.iu.edu|name|0|'|| l_current_timestamp;


--This converts the zimbraPreAuth key to a hash value to send securely to Zimbra to establish a login connection/authentication
l_mac := dbms_crypto.mac ( UTL_I18N.STRING_TO_RAW (l_preauth_values, 'UTF8'), dbms_crypto.hmac_sh1, UTL_I18N.STRING_TO_RAW (l_key, 'UTF8'));

--This actually makes the request to the Zimbra Server and does the preauthentication sending it the values that the zimbra preauth.txt file shows us to send, including the hmac value generated
http_response := utl_http.request('http://server.serv20.iu.edu/service/preauth?account=mbwalton@test.iu.edu'||chr(38)|| 'expires=0'|| chr(38)||'timestamp=' || l_current_timestamp || chr(38) ||'preauth=' || l_mac || chr(38) || 'redirectURL=http://server.serv20.iu.edu/service/home/mbwalton/Calendar?fmt=xml' );
--This will return xml data of all the CalendarsDBMS_OUTPUT.PUT_LINE(http_response);

END;

************************************************** ********

Here is the created function that we call above to turn the date into milliseconds because Oracle does not have a function for this.

create or replace function get_date_millis (i_date in date) return number is
begin
return to_number(
to_date(to_char((cast(i_date as timestamp)) at time zone 'gmt', 'yyyy.mm.dd hh24:mi:ss'),
'yyyy.mm.dd hh24:mi:ss')
- to_date('01.01.1970','dd.mm.yyyy')
) * (24 * 60 * 60 * 1000);
end;
/



IMPORTANT: You can find the preauth.txt file on your Zimbra server under the /opt/zimbra/docs path.
I hope this helps!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.