KNF:SSO notificatie middels JavaScript: verschil tussen versies

Uit Kennisnet Developers Documentatie
Naar navigatie springen Naar zoeken springen
Regel 2: Regel 2:
   
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
<p><a href="javascript:setCookie();">Set cookie</a></p>
+
<script type="text/javascript" charset="utf-8">
<p><a href="https://selfservice-t.entree.kennisnet.nl/accountbeheer" target="_blank">Accountbeheer openen</a></p>
+
var eloid = 'https://referentie-t.entree.kennisnet.nl/idp'; // EntityId
 
var elourl = 'https://referentie-t.entree.kennisnet.nl/referentie'; // ELO URL
<div id="ssonot"></div>
 
 
<script type="text/javascript" charset="utf-8">
 
var eloid = 'https://referentie-t.entree.kennisnet.nl/idp'; // EntityId
 
var elourl = 'https://referentie-t.entree.kennisnet.nl/referentie'; // ELO URL
 
   
function createCookie(name, value) {
+
function createCookie(name, value) {
document.cookie = name + "=" + value + "; path=/";
+
document.cookie = name + "=" + value + "; path=/";
  +
}
}
 
   
function readCookie(name) {
+
function readCookie(name) {
var nameEQ = name + "=";
+
var nameEQ = name + "=";
var ca = document.cookie.split(';');
+
var ca = document.cookie.split(';');
console.log(ca);
+
console.log(ca);
  +
 
for (var i=0;i < ca.length;i++) {
+
for (var i=0;i < ca.length;i++) {
var c = ca[i];
+
var c = ca[i];
while (c.charAt(0) == ' ') {
+
while (c.charAt(0) == ' ') {
c = c.substring(1,c.length);
+
c = c.substring(1,c.length);
  +
}
}
 
  +
 
if (c.indexOf(nameEQ) == 0) {
+
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length, c.length);
+
return c.substring(nameEQ.length, c.length);
  +
}
}
 
  +
}
}
 
  +
 
return null;
+
return null;
  +
}
}
 
  +
 
function setCookie() {
+
function setCookie() {
if (readCookie('entreePrelogin') != 'true') {
+
if (readCookie('entreePrelogin') != 'true') {
createCookie('entreePrelogin', 'true');
+
createCookie('entreePrelogin', 'true');
setSsoNotification();
+
setSsoNotification();
} else {
+
} else {
write("entreePrelogin cookie was already set!");
+
write("entreePrelogin cookie was already set!");
  +
}
}
 
}
+
}
   
function setSsoNotification() {
+
function setSsoNotification() {
var url = "https://aselect-t.entree.kennisnet.nl/openaselect/profiles/entree?id=" +
+
var url = "https://aselect-t.entree.kennisnet.nl/openaselect/profiles/entree?id=" +
eloid + "&url=" + encodeURIComponent(elourl);
+
eloid + "&url=" + encodeURIComponent(elourl);
  +
 
// Check if jQuery is avaiable
+
// Check if jQuery is avaiable
if (window.jQuery) {
+
if (window.jQuery) {
write("Using jQuery to set SSO Notification");
+
write("Using jQuery to set SSO Notification");
  +
 
// Use jQuery to ask the Entree Federation to set a SSO Notification
+
// Use jQuery to ask the Entree Federation to set a SSO Notification
$.ajax({
+
$.ajax({
url: url,
+
url: url,
dataType: 'jsonp'
+
dataType: 'jsonp'
}).always(function(data) {
+
}).always(function(data) {
write("Cookie is set");
+
write("Cookie is set");
});
+
});
} else {
+
} else {
write ("Using POJO to set SSO Notification");
+
write ("Using POJO to set SSO Notification");
  +
 
// This code can be used if no jQuery is available
+
// This code can be used if no jQuery is available
loadJSONP(url);
+
loadJSONP(url);
write("Cookie is set");
+
write("Cookie is set");
  +
}
}
 
  +
}
}
 
  +
 
function write(text) {
+
function write(text) {
document.getElementById('ssonot').innerText += text + "\r\n";
+
document.getElementById('ssonot').innerText += text + "\r\n";
  +
}
}
 
  +
 
// This function can be used if jQuery is not available
+
// This function can be used if jQuery is not available
function loadJSONP(url) {
+
function loadJSONP(url) {
var script = document.createElement('script');
+
var script = document.createElement('script');
script.type = 'text/javascript';
+
script.type = 'text/javascript';
script.src = url;
+
script.src = url;
   
// Setup handler
+
// Setup handler
window[name] = function(data) {
+
window[name] = function(data) {
callback.call((context || window), data);
+
callback.call((context || window), data);
document.getElementsByTagName('head')[0].removeChild(script);
+
document.getElementsByTagName('head')[0].removeChild(script);
script = null;
+
script = null;
delete window[name];
+
delete window[name];
};
+
};
  +
 
// Load JSON
+
// Load JSON
document.getElementsByTagName('head')[0].appendChild(script);
+
document.getElementsByTagName('head')[0].appendChild(script);
}
+
}
</script>
+
</script>
 
</syntaxhighlight>
 
</syntaxhighlight>
   

Versie van 28 sep 2018 07:35

Het SSO notificatie cookie kan geplaatst worden door, nadat de gebruiker is ingelogd in de ELO of schoolportaal, een AJAX call naar Entree Federatie uit te voeren.

   <script type="text/javascript" charset="utf-8">
		var eloid = 'https://referentie-t.entree.kennisnet.nl/idp';             // EntityId
		var elourl = 'https://referentie-t.entree.kennisnet.nl/referentie';     // ELO URL

		function createCookie(name, value) {
			document.cookie = name + "=" + value + "; path=/";
		}

		function readCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			console.log(ca);
			
			for (var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0) == ' ') {
					c = c.substring(1,c.length);
				}
					
				if (c.indexOf(nameEQ) == 0) {
					return c.substring(nameEQ.length, c.length);
				}
			}
			
			return null;
		}
		
		function setCookie() {
			if (readCookie('entreePrelogin') != 'true') {
				createCookie('entreePrelogin', 'true');
				setSsoNotification();
			} else {
				write("entreePrelogin cookie was already set!");
			}
		}            

		function setSsoNotification() {                
			var url = "https://aselect-t.entree.kennisnet.nl/openaselect/profiles/entree?id=" + 
				eloid + "&url=" + encodeURIComponent(elourl);
			
			// Check if jQuery is avaiable
			if (window.jQuery) {                  
				write("Using jQuery to set SSO Notification");
				
				// Use jQuery to ask the Entree Federation to set a SSO Notification                
				$.ajax({
					url: url,
					dataType: 'jsonp'                    
				}).always(function(data) {                    
					write("Cookie is set");
				});         
			} else {                
				write ("Using POJO to set SSO Notification");
				
				// This code can be used if no jQuery is available
				loadJSONP(url);
				write("Cookie is set");
			}
		}
		
		function write(text) {
			document.getElementById('ssonot').innerText += text + "\r\n";
		}
		
		// This function can be used if jQuery is not available    
		function loadJSONP(url) {
			var script = document.createElement('script');
			script.type = 'text/javascript';
			script.src = url;            

			// Setup handler
			window[name] = function(data) {
				callback.call((context || window), data);
				document.getElementsByTagName('head')[0].removeChild(script);
				script = null;
				delete window[name];
			};       
			
			// Load JSON
			document.getElementsByTagName('head')[0].appendChild(script);
		}            
	</script>


Foutmeldingen

Als de ingestelde identifier van de IdP niet bekend is binnen Entree Federatie zal de call resulteren in een 400 HTTP status code.
Wanneer de URL waarvandaan de call gedaan wordt niet aan de whitelist van Entree Federatie is toegevoegd zal de call ook een 400 HTTP status code opleveren.
Neem in deze gevallen contact op met Kennisnet.