Skip to content

Instantly share code, notes, and snippets.

@thejuan
Last active December 30, 2015 00:29
Show Gist options
  • Save thejuan/7750311 to your computer and use it in GitHub Desktop.
Save thejuan/7750311 to your computer and use it in GitHub Desktop.
JSONP ADFS Pre-Auth
//Requires Jquery 1.9+
var hasPreAuthenticated = false;
var webAPIHtmlPage = "http://webapi.somedomain/preauth.html"
function preauthenticate() {
//ADFS breaks Ajax requests, so we pre-authenticate the first call using an iFRAME and "authentication" page to get the cookies set
return $.Deferred(function (d) {
if (hasPreAuthenticated) {
console.log("Already pre-authenticated, skipping");
d.resolve();
return;
}
//Potentially could make this into a little popup layer
//that shows we are authenticating, and allows for re-authentication if needed
var iFrame = $("<iframe></iframe>");
iFrame.hide();
iFrame.appendTo("body");
iFrame.attr('src', webAPIHtmlPage);
iFrame.load(function () {
hasPreAuthenticated = true;
iFrame.remove();
d.resolve();
});
});
};
function makeCall(){
return authenticate().then(function () {
var options = //JSONP ajaxOptions
return $.ajax(options)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment