diff --git a/discojuice/README.md b/discojuice/README.md new file mode 100644 index 0000000..24ef607 --- /dev/null +++ b/discojuice/README.md @@ -0,0 +1,41 @@ +# Example for using the Shibboleth SP DiscoFeed for metadata filtering + +```javascript + +// base path of your application +var appUrl = "https://www.example.com"; + +// url to redirect to after the SSO login process was completed +var targetUrl = appUrl + "/login/shibboleth"; + +// setup discojuice with metadata filtering using the Shibboleth DiscoFeed +$('#disco-juice-login-link') + .DiscoJuice({ + "title" : "Shibboleth Login", + "subtitle" : "Please choose your organization from the list", + + "cookie" : false, + "location" : true, + "country" : false, + //"countryAPI" : "https://cdn.discojuice.org/country", + + "discoPath" : "https://cdn.discojuice.org/", + "redirectURL": appUrl + "/Shibboleth.sso/Login?target=" + encodeURIComponent(targetUrl) + "&entityID=", + "spentityid" : appUrl + "/Shibboleth.sso/Metadata", + "discofeed" : appUrl + '/Shibboleth.sso/DiscoFeed', //FFX + "metadata" : ['https://cdn.discojuice.org/feed/dfn'], // DFN-AAI + + "callback" : function (e, djc) { + var returnto = window.location.href; + var options = djc.parent.Utils.options; + var redirectURL = options.get('redirectURL'); + if (redirectURL) { + var newlocation = redirectURL + escape(e.entityID); + //console.log("Redirecting to " + newlocation); + window.location = newlocation; + } + else alert("DiscoJuice is misconfigured. You need to provide a redirectURL to send the user when a provider is selected."); + }, + + }); +``` diff --git a/discojuice/css/discojuice.css b/discojuice/css/discojuice.css index f900cdd..a777f9c 100644 --- a/discojuice/css/discojuice.css +++ b/discojuice/css/discojuice.css @@ -309,7 +309,7 @@ div.discojuice div.scroller a { color: #333; text-shadow: 0 1px #fff; font-size: 135%; - font-family: "Arial Narrow", "Arial", sans-serif; + font-family: "Arial", sans-serif; text-decoration: none; } diff --git a/discojuice/discojuice.control.js b/discojuice/discojuice.control.js index dd2ef5a..bb673f2 100644 --- a/discojuice/discojuice.control.js +++ b/discojuice/discojuice.control.js @@ -86,13 +86,16 @@ DiscoJuice.Control = { metadataurls = metadataurl; } + + // immediately set inlinemetadata if (typeof inlinemetadata === 'object' && inlinemetadata) { this.data = inlinemetadata; } - this.parent.Utils.log('metadataurl is ' + metadataurl); - if (!metadataurl) return; + //this.parent.Utils.log('metadataurl is ' + metadataurl); + console.log("METADATAURLS", metadataurls); + if (!metadataurls) return; // If SP EntityID is set in configuration make sure it is sent as a parameter // to the feed endpoint. @@ -101,36 +104,58 @@ DiscoJuice.Control = { parameters.entityID = discosettings.spentityid; } + // load metadata from urls that.parent.Utils.log('Setting up load() waiter'); waiter = DiscoJuice.Utils.waiter(function() { that.parent.Utils.log('load() waiter EXECUTE'); - that.postLoad(); + that.filterDiscoFeed(); }, 10000); - // console.log("METADATAURLS", metadataurls); for (i = 0; i < metadataurls.length; i++) { curmdurl = metadataurls[i]; waiter.runAction( function(notifyCompleted) { var j = i+1; - $.ajax({ - url: curmdurl, - dataType: 'jsonp', - jsonpCallback: function() { - // Important to use a reliable hash function for caching purposes - // same URL will always result in same callback function. - return '_' + (that.parent.Utils.murmurhash3_32_gc(curmdurl, 0)).toString(36); - }, - cache: true, - data: parameters, - success: function(data) { - that.data = $.merge(that.data, data); - //that.mergeData(data); - that.parent.Utils.log('Successfully loaded metadata (' + data.length + ') (' + j + ' of ' + metadataurls.length + ')'); - notifyCompleted(); - } - }); + + function successCallback(data) { + that.data = $.merge(that.data, data); + that.parent.Utils.log('Successfully loaded metadata (' + data.length + ') (' + j + ' of ' + metadataurls.length + ')'); + notifyCompleted(); + } + + + + var isLocalDomain = curmdurl.startsWith('/'); + if (!isLocalDomain) { + var curmdDomain = curmdurl.match(/^http[s]?:\/\/[^/]+/)[0]; + var curBrowserDomain = window.location.href.match(/^http[s]?:\/\/[^/]+/)[0]; + isLocalDomain = (curmdDomain == curBrowserDomain); + } + + if (isLocalDomain) { + console.log("Fetching metadata from local domain as JSON: " + curmdurl); + $.ajax({ + url: curmdurl, + dataType: 'json', + cache: true, + data: parameters, + success: successCallback + }); + + } + else { + console.log("Fetching metadata from external domain as JSONP: " + curmdurl); + var callback = '_' + (that.parent.Utils.murmurhash3_32_gc(curmdurl, 0)).toString(36); + $.ajax({ + url: curmdurl, + dataType: 'jsonp', + jasonp: callback, + cache: true, + data: parameters, + success: successCallback + }); + } }, // Callback function that will be executed if action completed after timeout. @@ -144,19 +169,79 @@ DiscoJuice.Control = { } waiter.startTimer(); - - - - }, + "filterDiscoFeed": function() { + var that = this; + + // load metadata from SP discoFeed url + var discofeedurl = this.parent.Utils.options.get('discofeed'); + if (!discofeedurl) that.postLoad(); + else { + that.parent.Utils.log('Setting up load() waiter'); + waiter = DiscoJuice.Utils.waiter(function() { + that.parent.Utils.log('load() waiter EXECUTE'); + that.postLoad(); + }, 5000); + + console.log("DISCOFEEDURL", discofeedurl); + waiter.runAction( + function(notifyCompleted) { + $.ajax({ + url: discofeedurl, + dataType: 'json', + cache: false, + success: function(data) { + var mappedData = []; + var filteredData = []; + + for (i = 0; i < data.length; i++) { + var entry = data[i]; + var mappedEntry = { + "title" : entry.DisplayNames[0].value, + "entityID" : entry.entityID, + }; + //console.log(mappedEntry); + mappedData.push(mappedEntry); + + // look for existing metadata entry and add all that are also found in discofeed + for (j = 0; j < that.data.length; j++) { + //console.log(that.data[j]); + //console.log(this.data[j].entityID + " vs " + mappedEntry.entityID); + if (that.data[j].entityID == mappedEntry.entityID) { + filteredData.push(that.data[j]); + } + } + } + //that.data = $.merge(that.data, mappedData); + console.log(filteredData); + that.data = filteredData; + + that.parent.Utils.log('Successfully loaded JSON metadata from discofeed '+discofeedurl+' (' + mappedData.length + ')'); + notifyCompleted(); + } + }); + }, + // Callback function that will be executed if action completed after timeout. + function () { + return function() { + that.ui.error("DiscoFeed retrieval from [" + discofeedurl + "] to slow. Ignoring response."); + } + }() + + ); + } + }, + "postLoad": function() { var that = this, waiter; if (!this.data) return; + + // Iterate through entities, and update title from DisplayNames to support Shibboleth integration. for(i = 0; i < this.data.length; i++) { if (!this.data[i].title) { @@ -574,7 +659,7 @@ DiscoJuice.Control = { "selectProvider": function(entityID, subID) { - // console.log('entityid: ' + entityID); + console.log('entityid: ' + entityID); var callback; @@ -1020,4 +1105,4 @@ DiscoJuice.Control = { } -}; \ No newline at end of file +}; diff --git a/discojuice/discojuice.hosted.js b/discojuice/discojuice.hosted.js index 67ab12e..393d2c3 100644 --- a/discojuice/discojuice.hosted.js +++ b/discojuice/discojuice.hosted.js @@ -72,4 +72,4 @@ DiscoJuice.Hosted = { }); } -}; \ No newline at end of file +};