XQuery/Digest Authentication

Motivation
The API you are using uses digest authentication, for example the Talis platform There is no direct support for this in the eXist httpclient module, but one can be written in XQuery.

The following implementation is based on the description and examples in Digest Authentication.

Modules and concepts

 * eXist httpclient : for basic POST operation
 * eXist util : for uuid generation and md5encoding

XQuery Module
Two functions transform between a comma-delimited list of name="value" pairs and an XML representation:

The first function takes strings in the following format: string="value",string1="value2",string3="value3"

Note that the replace function removes all double quotes from the right side of each expression.

Supporting Functions
The following two functions convert key-value encoded strings of this form:

key1="value1",key2="value2",key3="value3"

into XML structures of the form:

  

Here are the supporting functions:

Post With Digest Function
The main function handles a POST operation in two steps. The first POST will get a 401 response (should check this). The Digest is constructed and sent back with the second POST.

Note that on under eXist 1.4 the util:md5($string) function has been deprecated. You should now use util:hash($string, 'md5) function with the second parameter now the type of hash.

Example
In this example, an RDF file is POSTed to the Talis server.

declare namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; import module namespace http = "http://www.cems.uwe.ac.uk/xmlwiki/http" at "http.xqm";

let $rdf := doc("/db/RDF/dataset.rdf")/rdf:RDF let $path := "/store/mystore/meta" let $username := "myusername" let $password := "mypassword" let $host := "http://api.talis.com" let $header := 

return http:put-with-digest($host, $path, $username, $password, $rdf, $header)