< XQuery 
 
 
      Motivation
You want to use a very basic login process over a secure network such as a secure Intranet or over an SSL connection.
Method
We will used the base64 encoding and decoding tools to generate the right strings.
xquery version "1.0";
let $user := 'Aladdin'
let $password := 'open sesame'
let $credentials := concat($user, ':', $password)
let $encode := util:string-to-binary($credentials)
return
<results>
   <user>{$user}</user>
   <password>{$password}</password>
   <encode>{$encode}</encode>
</results>
Returns the following:
<results>
   <user>Aladdin</user>
   <password>open sesame</password>
   <encode>QWxhZGRpbjpvcGVuIHNlc2FtZQ==</encode>
</results>
Sample HTTP GET using Basic Authentication
xquery version "1.0";
declare function local:basic-get-http($uri,$username,$password) {
  let $credentials := concat($username,":",$password)
  let $credentials := util:string-to-binary($credentials)
  let $headers  := 
    <headers>
      <header name="Authorization" value="Basic {$credentials}"/>
    </headers>
  return httpclient:get(xs:anyURI($uri),false(), $headers)
};
let $host := "http://localhost:8080"
let $path :=  "/exist/rest/db/apps/terms/data/1.xml"
let $uri := concat($host, $path)
let $user := 'my-login'
let $password := 'my-password'
return local:basic-get-http($uri,$username,$password)
References
- http://en.wikipedia.org/wiki/Basic_access_authentication Wikipedia Entry on Basic Authentication
    This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.