Created
October 12, 2011 03:20
-
-
Save howarddierking/1280170 to your computer and use it in GitHub Desktop.
jQuery to handle an OAuth challenge response
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
function GetCommentsWithOAuth(){ | |
viewModel.comments([]); | |
$.ajax({ url: "/services/comments/oauth", | |
accepts: "application/json", | |
cache: false, | |
statusCode: { | |
200: function(data){ | |
viewModel.comments(data); | |
}, | |
401: function (jqXHR, textStatus, errorThrown) { | |
var wwwAuthHeaderValue = jqXHR.getResponseHeader("WWW-Authenticate"); | |
//get the location paramater and call it in an ajax modal | |
var re = /\w+\slocation="([/\.\?\=:&\w]+)"/i; | |
var results = re.exec(wwwAuthHeaderValue); | |
var authZServerUrl = results[1]; | |
alert("navigating to: " + authZServerUrl); | |
var w = window.open(authZServerUrl, null, 'width=900,height=600,toolbar=no,menubar=no'); | |
}, | |
403: function() { | |
alert('Sorry, are not authorized'); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment