Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created October 12, 2011 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save howarddierking/1280170 to your computer and use it in GitHub Desktop.
Save howarddierking/1280170 to your computer and use it in GitHub Desktop.
jQuery to handle an OAuth challenge response
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