Skip to content

Instantly share code, notes, and snippets.

@julien-c
Created July 31, 2012 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julien-c/3215194 to your computer and use it in GitHub Desktop.
Save julien-c/3215194 to your computer and use it in GitHub Desktop.
Simple AJAX authentication on top of tmhOAuth (Twitter sign-in)
$(document).ready(function(){
var user;
/* Sign in with Twitter */
// On load we check whether user's logged in or not:
$.get("api/oauth_ajax.php", null, function(data){
$("#spinner").hide();
if (data && data.id_str) {
// We have a signed-in Twitter user
}
});
$(".signin").click(function(){
$.ajax({
url: "api/oauth_ajax.php?start=1",
success: function(data){
if (data && data.authurl) {
window.location = data.authurl;
}
},
error: function(data){
// Display error message
}
});
});
$(".logout").click(function(e){
e.preventDefault();
$.ajax({
url: "api/oauth_ajax.php?wipe=1",
success: function(){
window.location.reload();
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment