Last active
December 30, 2015 00:29
-
-
Save thejuan/7750311 to your computer and use it in GitHub Desktop.
JSONP ADFS Pre-Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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