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! |