Created
December 2, 2011 03:21
-
-
Save mazharul/1421582 to your computer and use it in GitHub Desktop.
Facebook authentication code
This file contains hidden or 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
| <?php | |
| session_start(); | |
| $code = $_GET["code"]; | |
| $appId = $common->getAppId(); // your app id | |
| $myUrl = $_SERVER['HTTP_REFERER']; | |
| $appSecret = $common->secret(); //your app secret | |
| if(empty($code)) { | |
| $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection | |
| $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" | |
| . $appId . "&redirect_uri=" . urlencode($myUrl) . "&state=" | |
| . $_SESSION['state']."&scope=email,publish_stream,user_likes"; | |
| echo("<script> top.location.href='" . $dialog_url . "'</script>"); | |
| } | |
| if($_GET['state'] == $_SESSION['state']){ | |
| $token_url = "https://graph.facebook.com/oauth/access_token?" | |
| . "client_id=" . $appId . "&redirect_uri=" . urlencode($myUrl) | |
| . "&client_secret=" . $appSecret . "&code=" . $code; | |
| $response = file_get_contents($token_url); | |
| }else{ | |
| //CSRF protection | |
| //Somebody or some file is attacking | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment