Example: Retrieval of entities using the PersistenceService API

To illustrate how to use the PersistenceService API we will create and walk through a tiny persistence service call. This represents the smallest (and arguably least practically useful) implementation to update and store a new entity to the persistence service. While not useful as such it can serve as a starting point for further work. This example can be found as update-persistenceService.html in the thiss-ds-js distribution.

Start by creating an empty directory on a webserver and create in it an index.html with the following simple markup:

 1<!DOCTYPE html>
 2
 3<html lang="en">
 4<head>
 5  <meta charset="UTF-8">
 6  <meta name="viewport" content="width=device-width, initial-scale=1">
 7  <meta http-equiv="X-UA-Compatible" content="IE=10,11" />
 8  <script src="/js/jquery-3.1.1.min.js"></script>
 9  <title>SeamlessAccess.org - Upload entity to the PersistenceService</title>
10
11</head>
12<body>
13<h1>SeamlessAccess.org - Upload entity to the PersistenceService</h1>
14<script src="//unpkg.com/@theidentityselector/thiss-ds"></script>
15<script type="text/javascript">
16$(function() {
17
18  $('#myform').submit(function(event) {
19      event.preventDefault(); // prevents the form to submit
20
21      var formElements = $(this); // get all form elements
22      var entitydata = $('textarea#entitydata', formElements); // content of the textarea
23
24      $.ajax({
25        type: 'POST',
26        url: formElements.prop('action'),
27        accept: {
28          javascript: 'application/javascript'
29        },
30        data: formElements.serialize()
31
32    }).done(function(data) {
33
34      // retrieves the data from the textarea for submission to the persistence Service
35      console.log(entitydata.val());
36
37      // defines the context (i.e. key that will be used to store the data)
38      // thiss.io is the default context, the same is used when the context is not provided
39      var my_context = 'thiss.io'; // change this context value to persist entities in your own context (i.e. key).
40
41      var ps = new thiss.PersistenceService('https://service.seamlessaccess.org/ps/'); // prod url
42      //var ps = new thiss.PersistenceService('https://use.thiss.io/ps/'); // beta testing URL
43
44      var jsonformObj = JSON.parse(entitydata.val());
45
46      ps.update(my_context,jsonformObj)
47        .then(function(res) {
48            // Process the results
49            var myObjects = res.data;
50            for (i in myObjects) {
51              obj = myObjects[i];
52              console.log(obj);
53            };
54         }, function(err) {
55            // failed
56            console.log('failed ------------------------' + err);
57
58         });
59
60    });
61  });
62
63});
64
65</script>
66
67<form action="" id="myform">
68Populate the text area with the entityID you want to preserve.<br/>
69e.g.
70
71  <textarea id="entitydata" rows="20" cols="70" name="inputArea">
72{
73      "title": "Lancaster University",
74      "descr": "http://www.lancaster.ac.uk/",
75      "auth": "saml",
76      "entityID": "https://idp.lancs.ac.uk/idp/shibboleth",
77      "type": "idp",
78      "hidden": "false",
79      "scope": "lancaster.ac.uk",
80      "domain": "lancaster.ac.uk",
81      "name_tag": "LANCASTER",
82      "entity_icon_url": {
83        "url": "https://idp.lancs.ac.uk/logo-small.png",
84        "width": "157",
85        "height": "54"
86      }
87}
88</textarea>
89<input id="formbutton" type="submit" value="Submit">
90</form>
91
92
93<br>
94<p>Then check the discovery service at <a href="https://service.seamlessaccess.org/ds/" target="_blank">https://service.seamlessaccess.org/ds/</a></p>
95</body>
96</html>

Now load this page in your webserver. The institution will be persisted in the discovery service.