public function testLogoutURLFailsWithAppSession()
 {
     $helper = new FacebookRedirectLoginHelper(self::REDIRECT_URL, FacebookTestCredentials::$appId, FacebookTestCredentials::$appSecret);
     $helper->disableSessionStatusCheck();
     $session = FacebookTestHelper::getAppSession();
     $this->setExpectedException('Facebook\\FacebookSDKException', 'Cannot generate a Logout URL with an App Session.');
     $helper->getLogoutUrl($session, self::REDIRECT_URL);
 }
 public function testLogoutURL()
 {
     $helper = new FacebookRedirectLoginHelper(self::REDIRECT_URL, FacebookTestCredentials::$appId, FacebookTestCredentials::$appSecret);
     $logoutUrl = $helper->getLogoutUrl(FacebookTestHelper::$testSession, self::REDIRECT_URL);
     $params = array('next' => self::REDIRECT_URL, 'access_token' => FacebookTestHelper::$testSession->getToken());
     $expectedUrl = 'https://www.facebook.com/logout.php?';
     $this->assertTrue(strpos($logoutUrl, $expectedUrl) !== false);
     foreach ($params as $key => $value) {
         $this->assertTrue(strpos($logoutUrl, $key . '=' . urlencode($value)) !== false);
     }
 }
 public function __construct($currentUrl, $homeUrl)
 {
     $this->session = null;
     $this->loginUrl = '';
     $this->logoutUrl = '';
     $cleanUrl = false;
     try {
         if (session_id() == '') {
             session_start();
         }
         $loginHelper = new FacebookRedirectLoginHelper($currentUrl);
         // try to login from session token
         if (!empty($_SESSION['facebook_session_token'])) {
             $this->session = new FacebookSession($_SESSION['facebook_session_token']);
             if ($this->session) {
                 $this->session->validate();
             }
         }
         // try to login from redirect
         if (!$this->session) {
             $this->session = $loginHelper->getSessionFromRedirect();
             $cleanUrl = true;
         }
         // store access token
         if ($this->session) {
             $_SESSION['facebook_session_token'] = $this->session->getToken();
             if ($cleanUrl) {
                 header("HTTP/1.0 301 Moved Permanently");
                 header("Location: " . $currentUrl . '#top');
                 exit;
             }
             $this->logoutUrl = $loginHelper->getLogoutUrl($this->session, $homeUrl);
         } else {
             $this->loginUrl = $loginHelper->getLoginUrl();
         }
     } catch (\Exception $ex) {
         $this->session = null;
         $this->loginUrl = '';
         $this->logoutUrl = '';
     }
 }
        // Check if an access token has already been set.
        $session = new FacebookSession( $_SESSION['access_token'] );
    } else {
        // Get access token from the code parameter in the URL.
        $session = $helper->getSessionFromRedirect();
    }
} catch( FacebookRequestException $ex ) {

    // When Facebook returns an error.
    print_r( $ex );
} catch( \Exception $ex ) {

    // When validation fails or other local issues.
    print_r( $ex );
}
if ( isset( $session ) ) {

    // Retrieve & store the access token in a session.
    $_SESSION['access_token'] = $session->getToken();

    $logoutURL = $helper->getLogoutUrl( $session, 'http://your-app-domain.com/logout' );

    // Logged in
    echo '<h1>Successfully logged in! <a href="' . $logoutURL . '">Logout</a></h1>';
} else {

    // Generate the login URL for Facebook authentication.
    $loginUrl = $helper->getLoginUrl();
    $loginFacebookBtn =  '<a href="' . $loginUrl . '"><button type="button" class="btn btn-default col-sm-6"><i class="icon-large icon-facebook col-sm-2"></i>INICIA SESIÓN CON FACEBOOK</button></a>';
}
?>
예제 #5
0
파일: header.php 프로젝트: jthefang/Maptap
	      					<span class="fb_title">' . $user->getFirstName() . '</span>';
    } else {
        if (isset($_SESSION['user'])) {
            //logged in w/ TreeBoks
            echo '<img src = "images/profile_icon.png" height="18" width="18" id="fb_propic"/>
	      					<span class="fb_title">' . $_SESSION['user']['first_name'] . '</span>';
        }
    }
    echo '<img src="images/down_icon.png" id="show_more_icon" height="20" width="20" style="vertical-align: middle" />
	      					<img src="images/down_icon_selected.png" id="show_more_icon_selected" height="20" width="20" style="vertical-align: middle; display: none" />
	      				</a>
	      				<div id="user_options_menu_div">
	      					<ul class="user_list">
	      						<li class="user_list_item action">';
    if (isset($_SESSION['fb_token'])) {
        echo '<a href="' . $helper->getLogoutUrl($session, $siteURLs['fb_logout']) . '" class="user_list_item_link action"><span>Logout</span></a>';
    } else {
        if (isset($_SESSION['user'])) {
            //logged in w/ TreeBoks
            echo '<a href="logout.php" class="user_list_item_link action"><span>Logout</span></a>';
        }
    }
    echo '</li>
		      				</ul>
	      				</div>
	      			</div>
	      		</div>';
    /*---------------the propic is linked to my_projects.php for now-----------------*/
} else {
    //session does not exist
    // show login url
예제 #6
0
										<span class="btn btn-default col-md-12">
											Upload All
										</span>
									</a>
								</li>
								<li>
									<a href="#" id="move-selected-albums" class="center">
										<span class="btn btn-default col-md-12">
											Upload Selected
										</span>
									</a>
								</li>
								<li>
								
									<a href="<?php 
    echo $helper->getLogoutUrl($session, $fb_logout_url);
    ?>
" class="center">
										<span class="btn btn-default col-md-12">
										<span class="glyphicon glyphicon-log-out" aria-hidden="true" ></span>Logout
										</span>
									</a>
									
								</li>
							</ul>
						</div>
					</div>
				</nav>

				<div class="container" id="main-div">
				
if (isset($session)) {
    // save the session
    $_SESSION['fb_token'] = $session->getToken();
    // create a session using saved token or the new one we generated at login
    $session = new FacebookSession($session->getToken());
    // graph api request for user information
    $request_me = new FacebookRequest($session, 'GET', '/me');
    $response_me = $request_me->execute();
    $graphObject_me = $response_me->getGraphObject()->asArray();
    // graph api request for if user likes the page (id)
    $request_page_like = new FacebookRequest($session, 'GET', "/me/likes/PAGE_ID");
    $response_page_like = $request_page_like->execute();
    // get response
    $graphObject_page_like = $response_page_like->getGraphObject()->asArray();
    // print logout url using session and redirect_uri (logout.php page should destroy the session)
    echo '<a href="' . $helper->getLogoutUrl($session, 'logout.php') . '">Logout</a>';
}
?>



<!DOCTYPE html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="description" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<title>Facebook LikePage</title>

	<!-- LÈ CSS -->
FacebookSession::setDefaultApplication(APP_ID, APP_SECRET);
$helper = new FacebookRedirectLoginHelper(REDIRECT_URL);
try {
    $session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
    // When Facebook returns an error
} catch (Exception $ex) {
    // When validation fails or other local issues
}
if (isset($session)) {
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graphObject = $response->getGraphObject();
    echo "name =" . $graphObject->getProperty('name') . "<br>";
    echo "email =" . $graphObject->getProperty('email') . "<br>";
    echo "first_name =" . $graphObject->getProperty('first_name') . "<br>";
    echo "last_name =" . $graphObject->getProperty('last_name') . "<br>";
    echo "link =" . $graphObject->getProperty('link') . "<br>";
    echo "image =" . $graphObject->getProperty('image') . "<br>";
    echo '<img src="https://graph.facebook.com/' . $graphObject->getProperty('id') . '/picture?type=square" />';
    echo '<a href = ' . $helper->getLogoutUrl($session, 'http://localhost/foodpost/public/index.php') . '> Logout </a>';
} else {
    echo ' 
  <a href="' . $helper->getLoginUrl(array('scope' => ' email,
                                                              user_birthday,
                                                              user_location,
                                                              user_work_history,
                                                              user_about_me,
                                                              user_hometown
                                                              ')) . '">Login</a>';
}
예제 #9
0
        $fb_session = new FacebookSession($_SESSION['access_token']);
    } else {
        // Get access token from the code parameter in the URL.
        $fb_session = $helper->getSessionFromRedirect();
    }
} catch (FacebookRequestException $ex) {
    // When Facebook returns an error.
    print_r($ex);
} catch (Exception $ex) {
    // When validation fails or other local issues.
    print_r($ex);
}
if (isset($fb_session)) {
    // Retrieve & store the access token in a session.
    $_SESSION['access_token'] = $fb_session->getToken();
    $logoutURL = $helper->getLogoutUrl($fb_session, Yii::app()->getBaseUrl(true) . '/index.php/user/logout');
    // Logged in
    echo CHtml::button('Logout', array('class' => 'btn', 'submit' => $logoutURL));
    //echo 'Successfully logged in! <a href="' . $logoutURL . '">Logout</a>';
} else {
    // Generate the login URL for Facebook authentication.
    $loginUrl = $helper->getLoginUrl($permissions);
    echo CHtml::button('Login', array('class' => 'btn', 'submit' => $loginUrl));
    //   echo CHtml::button('Login', array('class' => 'btn', 'submit' => array($loginUrl, array('fb_session'=>$redirect_url))));
}
if (isset($fb_session)) {
    // graph api request for user data
    $request = new FacebookRequest($fb_session, 'GET', '/me');
    $response = $request->execute();
    // get response
    $graphObject = $response->getGraphObject();
예제 #10
0
 $usr = new mnpBD('usuarios');
 $usr->insertar($campos, $datos);
 $_SESSION['usuario']['id'] = mysql_insert_id();
 $_SESSION['usuario']['nombre'] = $graphObject['first_name'];
 $_SESSION['usuario']['foto'] = $graphObject_foto['url'];
 $_SESSION['usuario']['tipo'] = "0";
 $campos = "id_usuario,red_social,id_red_social";
 $datos = array($_SESSION['usuario']['id'], 'facebook', $graphObject['id']);
 $usr = new mnpBD('redes_sociales');
 $usr->insertar($campos, $datos);
 $campos = "usuario_id, nombre_v, apellidos_v, email_v, telefono_v, especialidad_v, pais_v, estado_v, institucion_v";
 $datos = array($_SESSION['usuario']['id'], 1, 1, 0, 1, 1, 1, 1, 1);
 $usr = new mnpBD('campos_visibles');
 $usr->insertar($campos, $datos);
 //---------------------------------------------------------------------
 $logout = $helper->getLogoutUrl($session, 'http://www.actualizacionmedica.net/logout.php');
 //-------------establecemos cookie----------------------------------------------------
 mt_srand(time());
 $rand = mt_rand(1000000, 9999999);
 setcookie("id", $_SESSION['usuario']['id'], time() + 60 * 60 * 24 * 365);
 setcookie("marca", $rand, time() + 60 * 60 * 24 * 365);
 $campos = "cookie";
 $valores = array($rand);
 $condicion = " id=" . $_SESSION['usuario']['id'];
 $usr = new mnpBD('usuarios');
 $usr->actualizar($campos, $valores, $condicion);
 //---------------------------------------------------------------------------------------
 $campos = 'usuario_id, ip, dispositivo, fecha_hora';
 $datos = array($_SESSION['usuario']['id'], get_real_ip(), strtolower($_SERVER['HTTP_USER_AGENT']), date("Y-m-d H:i:s"));
 $usr = new mnpBD('logeos');
 $usr->insertar($campos, $datos);
    try {
        $session = $helper->getSessionFromRedirect();
    } catch (FacebookRequestException $ex) {
        // When Facebook returns an error
        // handle this better in production code
        print_r($ex);
    } catch (Exception $ex) {
        // When validation fails or other local issues
        // handle this better in production code
        print_r($ex);
    }
}
// see if we have a session
if (isset($session)) {
    // save the session
    $_SESSION['fb_token'] = $session->getToken();
    // create a session using saved token or the new one we generated at login
    $session = new FacebookSession($session->getToken());
    // graph api request for user data
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    // get response
    $graphObject = $response->getGraphObject()->asArray();
    // print profile data
    echo '<pre>' . print_r($graphObject, 1) . '</pre>';
    // print logout url using session and redirect_uri (logout.php page should destroy the session)
    echo '<a href="' . $helper->getLogoutUrl($session, $logout_url) . '">Logout</a>';
} else {
    // show login url
    echo '<a href="' . $helper->getLoginUrl(array('email', 'user_friends')) . '">Login</a>';
}
예제 #12
0
      							<li id="no_notifications" class="user_list_item"><a class="user_list_item_link">No new notifications</a></li>
      							<!--<li class="user_list_item action"><a class="user_list_item_link action"></a></li>-->
      						</ul>
      					</div>
      				</div>
      				<div id="user_profile" class="fb_user_button">
	      				<a class="fb_fxn_link">
	      					<img src = "https://graph.facebook.com/' . $userId . '/picture?type=square&height=18&width=18" id="fb_propic"/>
	      					<span class="fb_title">' . $user->getFirstName() . '</span>
	      					<img src="images/down_icon.png" id="show_more_icon" height="20" width="20" style="vertical-align: middle" />
	      					<img src="images/down_icon_selected.png" id="show_more_icon_selected" height="20" width="20" style="vertical-align: middle; display: none" />
	      				</a>
	      				<div id="user_options_menu_div">
	      					<ul class="user_list">
	      						<li class="user_list_item action">
			      					<a href="' . $helper->getLogoutUrl($session, 'http://localhost/TreeBox/facebook/logout.php') . '" class="user_list_item_link action"><span>Logout</span></a>
					      		</li>
		      				</ul>
	      				</div>
	      			</div>
	      		</div>';
    /*---------------the propic is linked to my_projects.php for now-----------------*/
} else {
    //session does not exist
    // show login url
    echo '<ul id="navbar_menu">
	      			<li><a href="index.php"><img src="images/home_icon.png" class="navbar_icon"/><span class="navbar_link">Home</span></a></li>
	      		</ul>
	      		<div class="block_login">
	  				<div class="btn-fb-button">
	  					<a href="' . $helper->getLoginUrl(array('email', 'user_friends')) . '"><span class="icon"></span>
예제 #13
0
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Facebook Login</title>
  </head>
  <body>
  
            <?php 
if (isset($session)) {
    // print logout url using session and redirect_uri (logout.php page should destroy the session)
    // EDIT THIS LINE ********************************************// EDIT THIS LINE ********************************************
    echo '<dd><a href="' . $helper->getLogoutUrl($session, 'http://www.URL/PATH/TO/actions/fbLogout.php') . '">Logout' . "&nbsp" . $graphObject['first_name'] . "&nbsp" . $graphObject['last_name'] . '</a>';
} else {
    // show login url
    echo '<a href="' . $helper->getLoginUrl(array('email, user_birthday, user_about_me')) . '">Login With Facebook</a>';
}
?>
    
          </div>
        </div>
       </menu>              

<?php 
// DUMPING ALL DATA IN $graphObject for you to see everything is working.
var_dump($graphObject);
?>
예제 #14
0
        // When Facebook returns an error
    } catch (Exception $ex) {
        // When validation fails or other local issues
        echo $ex->message;
    }
}
// see if we have a session
if (isset($session)) {
    // save the session
    $_SESSION['fb_token'] = $session->getToken();
    // create a session using saved token or the new one we generated at login
    $session = new FacebookSession($session->getToken());
    // graph api request for user data
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graphObject = $response->getGraphObject()->asArray();
    $_SESSION['valid'] = true;
    $_SESSION['timeout'] = time();
    $_SESSION['FB'] = true;
    $_SESSION['usernameFB'] = $graphObject['name'];
    $_SESSION['idFB'] = $graphObject['id'];
    $_SESSION['first_nameFB'] = $graphObject['first_name'];
    $_SESSION['last_nameFB'] = $graphObject['last_name'];
    $_SESSION['genderFB'] = $graphObject['gender'];
    // logout and destroy the session, redirect url must be absolute url
    $linkLogout = $helper->getLogoutUrl($session, 'http://todaythoughts.com/CS4880FB/redirect.php?action=logout');
    $_SESSION['logoutUrlFB'] = $linkLogout;
    header('Location: index.php');
} else {
    header('Location: ' . $helper->getLoginUrl());
}
예제 #15
0
    $graphObject1 = $response1->getGraphObject()->asArray();
    // print friendslist data
    echo '<pre>' . print_r($graphObject1, 1) . '</pre>';
    // graph api request for user friends
    $request = new FacebookRequest($session, 'GET', '/me/picture', array('redirect' => false, 'height' => '200', 'type' => 'normal', 'width' => '200'));
    $response = $request->execute();
    $graphObject = $response->getGraphObject()->asArray();
    echo "<img src = 'https://graph.facebook.com/{$userId}/picture?type=small' />";
    echo "<img src = 'https://graph.facebook.com/{$userId}/picture?type=square' />";
    echo "<img src = 'https://graph.facebook.com/{$userId}/picture?type=square&height=28&width=28' />";
    //echo "<img src='{$graphObject["url"]}'/>";
    echo '<pre>' . print_r($graphObject, 1) . '</pre>';
    // print logout url using session and redirect_uri (logout.php page should destroy the session)
    echo '<div class="block_logout">
              <div class="btn-fb-button">
                <a href="' . $helper->getLogoutUrl($session, 'http://localhost/TreeBox/facebook/logout.php') . '"><span class="title">Logout of Facebook</span></a>
              </div>
            </div>';
} else {
    // show login url
    echo '<div class="block_login">
              <div class="btn-fb-button">
                <a href="' . $helper->getLoginUrl(array('user_friends')) . '"><span class="icon"></span>
                  <span class="title">Login with Facebook</span></a>
              </div>
            </div>';
}
?>
  </body>
</html>