Last active
August 29, 2015 14:09
-
-
Save mimming/45f58e608e8a4d84b634 to your computer and use it in GitHub Desktop.
Facebook and Twitter auth with redirects
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
<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