Created
July 31, 2012 08:56
-
-
Save julien-c/3215194 to your computer and use it in GitHub Desktop.
Simple AJAX authentication on top of tmhOAuth (Twitter sign-in)
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
$(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