Using Digest Authentication to Insert Triples


Insert triples using Digest Authentication against the Virtuoso /sparql-auth endpoint.


To simplify data management by using HTTP digest authentication.


Here is a sample example showcasing how to insert triples in Virtuoso Quad store using Digest Authentication in a simple HTML 5 form with embedded AJAX:


This example demonstrates how Virtuoso user can insert triples into the Virtuoso Quad Store using Digest authentication against the Virtuoso "/sparql-auth" endpoint. The implementation is done on the base of simple html form using HTML 5 and AJAX:

<html lang="en">

<script type="text/javascript">
    function authenticate()
        vgraphuri   = document.demo.graphuri.value ;
        vsubject    = document.demo.subject.value ;
        vpredicate  = document.demo.predicate.value ;
        vobject     = document.demo.object.value ;
        vuser       = document.demo.username.value ;
        vpassword   = document.demo.userpassword.value ;
        var q = "INSERT INTO GRAPH " + vgraphuri + " { " + vsubject + " " + vpredicate + " " + vobject + "  . } " ;
        var xhr = new XMLHttpRequest();
          if (xhr.readyState==4 && xhr.status==200)
          if (xhr.readyState==4 && xhr.status==401)
              alert("Error: Invalid credentials or insufficient rights to perform the operation."); 
         if (xhr.readyState==4 && xhr.status==500)
         if (xhr.readyState==4 && xhr.status==400)
        }"POST", "/sparql-auth/", false, vuser, vpassword);
	xhr.send("query=" + encodeURIComponent (q));
  1. To be able to perform updates to the Quad Store, a Virtuoso user account should have specific settings done:
    1. Go to http://host:port/conductor

    2. Enter admin credentials
    3. Go to "System Admin" -> "Users"

    4. Click "Create New Account". Optionally, you can apply the settings to existing user too.
    5. In the presented form:
      • enter "Account name", for ex. demo
      • enter "Password",
      • change "User type" to "SQL/ODBC and WebDAV",
      • for "DAV Home Path" hatch the "create" check-box,
      • change "Quata" to 5,
      • Select from "Account Roles" the role "SPARQL_UPDATE" and move to "Selected" list

    6. Click "Save"
    7. The new user "demo" should be created and displayed in the users list:

  2. Now when we have an user that can update the Quad Store data, we will demonstrate how this user will insert a triple. Place the following demo.html file at your server, so for ex. it to be accessible from http://host:port/mydemo:

  3. The presented form offers 4 fields -- one for graph URI, respectively one for subject, object and predicate values. Each of these fields has predefined values that can be changed to other preferable. Enter for the created user from above its credentials and click "Insert".
  4. On a successful insert, a message as below will be presented:

  5. In case some of the fields graphuri, subject, object or predicate are invalid, an error handler message will be presented:

  6. In case the user has provided wrong credentials or has no rights to update the Quad Store, a message as per bellow will be presented: