0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 * Logging Users out of your App
|
|
5 *
|
|
6 * @author Xavier Barbosa
|
|
7 * @since 13 February, 2013
|
|
8 * @link https://developers.facebook.com/docs/howtos/login/server-side-logout/
|
|
9 **/
|
|
10
|
|
11 use Mute\Facebook\App;
|
|
12
|
|
13 /**
|
|
14 * Default params
|
|
15 **/
|
|
16
|
|
17 $app_id = "YOUR_APP_ID";
|
|
18 $app_secret = "YOUR_APP_SECRET";
|
|
19 $my_url = "YOUR_LOGOUT_URL";
|
|
20
|
|
21 session_start();
|
|
22
|
|
23 /**
|
|
24 * The process
|
|
25 **/
|
|
26
|
|
27 $app = new App($app_id, $app_secret);
|
|
28
|
|
29
|
|
30 $code = $_REQUEST["code"];
|
|
31
|
|
32 if($_SESSION['state'] && ($_SESSION['state'] === $_REQUEST['state'])) {
|
|
33 $params = $app->getOAuth()->getAccessToken($code);
|
|
34 $_SESSION['access_token'] = $params['access_token'];
|
|
35
|
|
36 $user = $app->get('me', array(
|
|
37 'access_token' => $params['access_token'],
|
|
38 ));
|
|
39 echo("Hello " . $user->name);
|
|
40
|
|
41 // Logout button code added below
|
|
42 echo "<br><a href='logout.php'>Click to log out</a>";
|
|
43 }
|
|
44 else {
|
|
45 echo("The state does not match. You may be a victim of CSRF.");
|
|
46 die;
|
|
47 }
|
|
48
|
|
49 $token = $_SESSION["access_token"];
|
|
50 if($token) {
|
|
51 $result = $app->delete('me/permissions', array(
|
|
52 'access_token' => $token,
|
|
53 ));
|
|
54 if($result) {
|
|
55 session_destroy();
|
|
56 echo "User is now logged out.";
|
|
57 }
|
|
58 } else {
|
|
59 echo("User already logged out.");
|
|
60 }
|