KNF:SSO notificatie middels JavaScript/en

Uit Kennisnet Developers Documentatie
Naar navigatie springen Naar zoeken springen

The SSO notification cookie can be placed, after the user has logged in on the schoolportal, with an AJAX call to Entree Federatie.

For the implementation use the following script. The following values need te be adjusted: :

  1. eloid: The unique identifier of the Identity Provider as known in Entree Federatie. This is the entity ID of the IdP and can be found here: https://aselect.entree.kennisnet.nl/openaselect/sso/wayfsearch2?type=getAll&spCode
  2. elourl: The URL of the schoolportal where the call comes from.

Important: Before you can use the SSO notification, the URL needs to be added on the whitelist. You can send the URL via an ticket Kennisnet.

Example of the script in jQuery and native JavaScript.

<script type="text/javascript" charset="utf-8">
    var eloid = '';      // EntityId
    var elourl = '';     // ELO URL


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


    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');

        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();
        }
    }


    function setSsoNotification() {
        var url = "https://ssonot.aselect.entree.kennisnet.nl/openaselect/profiles/entree?id=" +  eloid + "&url=" + encodeURIComponent(elourl);

        // Check if jQuery is avaiable
        if (window.jQuery) {
            // Use jQuery to ask the Entree Federation to set a SSO Notification
            $.ajax({
                url: url,
                dataType: 'jsonp'
                }).always(function(data) {});
        } else {
            // This code can be used if no jQuery is available
            loadJSONP(url);
        }
    }


    // 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>