Skip to content

Instantly share code, notes, and snippets.

@mimming
Last active August 29, 2015 14:09
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 mimming/45f58e608e8a4d84b634 to your computer and use it in GitHub Desktop.
Save mimming/45f58e608e8a4d84b634 to your computer and use it in GitHub Desktop.
Facebook and Twitter auth with redirects
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.1.2/firebase.js"></script>
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script>
$( document ).ready(function() {
var myFirebaseRef = new Firebase("https://test-firebase-please-ignore.firebaseio.com/");
$("#authFacebook").click(function(event) {
myFirebaseRef.authWithOAuthRedirect("facebook", function(error) {
console.log("auth'd Facebook. Error state here (if any) " + error);
});
});
$("#authTwitter").click(function(event) {
myFirebaseRef.authWithOAuthRedirect("twitter", function(error) {
console.log("auth'd Twitter. Error state here (if any) " + error);
});
});
$("#logout").click(function(event) {
myFirebaseRef.unauth();
});
myFirebaseRef.onAuth(function(authData) {
if (authData) {
console.log("User ID: " + authData.uid + ", Provider: " + authData.provider);
} else {
console.log("logged out");
}
});
});
</script>
</head>
<body>
<button id="authFacebook">Facebook</button>
<button id="authTwitter">Twitter</button>
<button id="logout">log out</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment