Ejemplo n.º 1
0
 /**
  * 
  * Tells if the current page load appears to be the result of
  * an attempt to log in.
  * 
  * @return bool
  * 
  */
 public function isLoginRequest()
 {
     // check for a facebook session
     if ($this->_request->cookie('fbs_' . $this->_facebook->getAppId())) {
         return true;
     }
 }
Ejemplo n.º 2
0
function facebook_init()
{
    require 'src/facebook.php';
    global $facebook;
    $facebook = new Facebook(array('appId' => FB_KEY, 'secret' => FB_SECRET));
    if (!empty($_SESSION) && !empty($_SESSION['fb_code'])) {
        $url = "https://graph.facebook.com/oauth/access_token?";
        $params = array();
        $params[] = 'client_id=' . $facebook->getAppId();
        $params[] = 'redirect_uri=' . 'http://' . HOST . get_url('/facebook/auth/');
        $params[] = 'client_secret=' . $facebook->getApiSecret();
        $params[] = 'code=' . $_SESSION['fb_code'];
        $url .= implode('&', $params);
        $data = explode('&', get_data($url));
        foreach ($data as &$d) {
            $d = explode('=', $d);
            if ($d[0] == 'access_token') {
                $_SESSION['fb_access_token'] = $d[1];
            } elseif ($d[0] == 'expires') {
                $_SESSION['fb_at_expires'] = time() + $d[1];
            }
        }
    }
    if (array_key_exists('fb_access_token', $_SESSION)) {
        if ($_SESSION['fb_at_expires'] > time()) {
            $facebook->setAccessToken($_SESSION['fb_access_token']);
            unset($_SESSION['fb_code']);
        }
    }
}
Ejemplo n.º 3
0
    /**
     * 
     * Generates the script block required by Facebook.
     * 
     * @return void
     * 
     */
    protected function _postConstruct()
    {
        parent::_postConstruct();
        // retain the facebook dependency
        $this->_facebook = Solar::dependency('Facebook', $this->_config['facebook']);
        // add the FB script to the foot helper
        $href = "http://connect.facebook.net/en_US/all.js";
        $this->_view->foot()->addScript($href);
        // initialize the application and set up login event subscription,
        // also done via the foot helper
        $appid = $this->_facebook->getAppId();
        $inline = <<<INLINE
FB.init({appId: '{$appid}', xfbml: true, cookie: true});
FB.Event.subscribe('auth.login', function(response) {
  window.location.reload();
});
INLINE;
        $this->_view->foot()->addScriptInline($inline);
    }
Ejemplo n.º 4
0
 /**
  * 
  * Tells if the current page load appears to be the result of
  * an attempt to log out, if so resets the facebook cookie
  * 
  * @return bool
  * 
  */
 public function isLogoutRequest()
 {
     if ($this->_request->isCsrf()) {
         return false;
     }
     $method = $this->_config['method'];
     if ($this->_request->{$method}($this->_config['source_process']) == $this->_config['process']) {
         setcookie('fbs_' . $this->_facebook->getAppId(), "", time() - 36000);
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 public function getAccess($token, $secret, $verifier)
 {
     $code = JRequest::getVar('code');
     $params = array('client_id' => parent::getAppId(), 'redirect_uri' => $this->callback, 'client_secret' => parent::getApiSecret(), 'code' => $code);
     $token = parent::_oauthRequest(parent::getUrl('graph', '/oauth/access_token'), $params);
     $token = str_ireplace('access_token=', '', $token);
     $obj = new stdClass();
     $obj->token = $token;
     $obj->secret = 'facebook';
     $obj->params = '';
     return $obj;
 }
Ejemplo n.º 6
0
function Users_before_Q_objects()
{
    $app = Q_Config::expect('Q', 'app');
    $fb_info = Q_Config::get('Users', 'facebookApps', $app, null);
    // We sometimes pass this in the request, for browsers like Safari
    // that don't allow setting of cookies using javascript inside 3rd party iframes
    if (!empty($fb_info['appId']) and !empty($_REQUEST['Users']['facebook_authResponse'])) {
        $appId = $fb_info['appId'];
        $auth_response = $_REQUEST['Users']['facebook_authResponse'];
        if (is_array($auth_response)) {
            if ($auth_response) {
                $cookie = $auth_response['signedRequest'];
                $expires = 0;
            } else {
                $cookie = "";
                $expires = 1;
            }
            try {
                $facebook = new Facebook(array('appId' => $fb_info['appId'], 'secret' => $fb_info['secret'], 'fileUpload' => true));
                $cookie_name = 'fbsr_' . $facebook->getAppId();
                if (!empty($_SERVER['HTTP_HOST'])) {
                    Q_Response::setCookie($cookie_name, $cookie, $expires);
                }
            } catch (Exception $e) {
                // do nothing
            }
        }
    }
    $uri = Q_Dispatcher::uri();
    $actions = array('activate' => true);
    if ($uri->module === 'Users' and isset($actions[$uri->action])) {
        Q::event("Users/{$uri->action}/objects");
    }
    // Fire an event for hooking into, if necessary
    Q::event('Users/objects', array(), 'after');
}
 /**
  * Returns the app id
  *
  * @return string
  */
 public function getAppId()
 {
     return $this->facebook->getAppId();
 }
Ejemplo n.º 8
0
 public function testSetAppId()
 {
     $facebook = new Facebook(array('appId' => self::APP_ID, 'secret' => self::SECRET));
     $facebook->setAppId('dummy');
     $this->assertEquals($facebook->getAppId(), 'dummy', 'Expect the App ID to be dummy.');
 }
Ejemplo n.º 9
0
<?php

require 'php-sdk/facebook.php';
$facebook = new Facebook(array('appId' => '124593811064320', 'secret' => '21edb9fabde67d1f0718e13ddcc2ac4f'));
setcookie('fbs_' . $facebook->getAppId(), ' ', time() - 100, '/', 'atetnowski.com/facebook');
$facebook->destroySession();
header('Location: index.php');
<?php

/**
/* This code verifies that the authorization succeded. 
**/
//Include libraries
require '../facebook.php';
require '../appengine_functions.php';
//Initialize Facebook's PHP library
$config = array('appId' => '140229329376512', 'secret' => '198fb6f72dfb3a029d410d98e3beb203', 'cookie' => true, 'domain' => true);
$facebook_client = new Facebook($config);
//Initialize variables
$app_id = $facebook_client->getAppId();
$app_secret = $facebook_client->getApiSecret();
$CANVAS_URL = 'http://apps.facebook.com/russ_myfirstapp/';
//Get the access token from Facebook by supplying the App ID & Secret.
$params = array('client_id' => $app_id, 'type' => 'client_cred', 'client_secret' => $app_secret);
$url = "https://graph.facebook.com/oauth/access_token";
$access_token = make_request($url, $params);
// creates a POST request with $params as the parameters.
$access_token = substr($access_token, strpos($access_token, "=") + 1, strlen($access_token));
//If the access token is not present, something went wrong
//so display an error, else, redirect to canvas page.
if ($access_token) {
    header('Location: ' . $CANVAS_URL);
} else {
    echo 'An error occurred';
}
exit;
Ejemplo n.º 11
0
if (SpoonSession::exists('public_uid')) {
    // Create our Application instance (replace this with your appId and secret).
    $facebook = new Facebook(array('appId' => '118234134911012', 'secret' => 'a83b1fbf766dcf41a8238a13f53690bd', 'cookie' => true));
    //$facebook->setSession(null);
    $session = $facebook->getSession();
    //spoon::dump($session);
    // Session based API call.
    if ($session) {
        try {
            $db = new SpoonDatabase('mysql', 'localhost', 'xqdchsmn_public', 'pRAcHU8Ajath7qa3', 'xqdchsmn_public');
            $record = array();
            //$record['fb_access_token'] = $facebook->getAccessToken();
            $record['fb_uid'] = $facebook->getUser();
            $record['fb_publish_stream'] = true;
            $uid = SpoonSession::get('public_uid');
            $rows = $db->update('users', $record, 'user_id = ?', $uid);
            SpoonHTTP::redirect('dashboardSettings.php');
        } catch (FacebookApiException $e) {
            error_log($e);
        }
    } else {
        $tpl->assign('fbcbutton', '<fb:login-button perms="email,publish_stream"></fb:login-button>');
        //http://developers.facebook.com/docs/authentication/permissions
    }
    // facebook javascript
    $tpl->assign('appid', $facebook->getAppId());
} else {
    SpoonHTTP::redirect('login.php');
}
// show the output
$tpl->display('templates/facebookconnect.tpl');
Ejemplo n.º 12
0
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
require 'src/facebook.php';
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array('appId' => 'youkey', 'secret' => 'yoursecret'));
if (isset($_GET['logout'])) {
    setcookie('fbs_' . $facebook->getAppId(), '', time() - 100, '/', 'domain.com');
    session_destroy();
    header('Location:' . $_SERVER['HTTP_REFERER']);
    exit;
}
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
Ejemplo n.º 13
0
    print_r($bindings);
    print_r($time);
    print_r($name);
});
*/
$app->hook("slim.before", function () use($facebook) {
    /* IE has problems with crossdomain cookies. */
    header('P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
    /* When using FB.ui("oauth", ...) */
    /* Apparently FB.login() is now inline so this is not necessary */
    /* anymore http://goo.gl/22sfO */
    if (isset($_REQUEST["session"])) {
        $session_data = json_decode($_REQUEST["session"], true);
        $url = "https://graph.facebook.com/oauth/exchange_sessions";
        $curl = curl_init($url);
        $post = array("client_id" => $facebook->getAppId(), "client_secret" => $facebook->getApiSecret(), "sessions" => $session_data["session_key"]);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($curl);
        curl_close($curl);
        $exchange_data = json_decode($response, true);
        $access_token = $exchange_data[0]["access_token"];
        /* Save access toke to session since not all  */
        /* requests come from Facebook iframe. */
        $_SESSION["access_token"] = $access_token;
    }
    /* When using FB.login(...) or already installed. */
    if (isset($_REQUEST["signed_request"])) {
        $signed_request = $facebook->getSignedRequest();
        if (isset($signed_request["oauth_token"])) {
 /**
  * Generates a simple app access token
  *
  * @link https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens
  *
  * @param \Facebook $facebook
  *
  * @return string
  */
 public function getSimpleAppToken(\Facebook $facebook)
 {
     return "{$facebook->getAppId()}|{$facebook->getAppSecret()}";
 }
Ejemplo n.º 15
0
    public function fbButton()
    {
        $this->objMods = $this->getObject('modules', 'modulecatalogue');
        $this->objDbSysconfig = $this->getObject('dbsysconfig', 'sysconfig');
        $show = $this->objDbSysconfig->getValue('show_fbconnect_auth', 'security');
        if ($this->objMods->checkIfRegistered('facebookapps') && strtolower($show) == 'true') {
            include $this->getResourcePath('facebook.php', 'facebookapps');
            $apikey = $this->objDbSysconfig->getValue('apikey', 'facebookapps');
            $secret = $this->objDbSysconfig->getValue('apisecret', 'facebookapps');
            $appId = $this->objDbSysconfig->getValue('apid', 'facebookapps');
            // Create our Application instance (replace this with your appId and secret).
            $facebook = new Facebook(array('appId' => $appId, 'secret' => $secret, 'cookie' => true));
            $session = $facebook->getSession();
            $fbappid = $facebook->getAppId();
            $jsess = json_encode($session);
            $reloadurl = $this->uri(array('module' => '_default'));
            $onloginurl = $this->uri(array('module' => 'security', 'action' => 'fbconnect'));
            $fb = '<div id="fb-root"></div>';
            $fb .= '<script>
                         window.fbAsyncInit = function() {
                             FB.init({
                                 appId   : \'' . $fbappid . '\',
                                 session : ' . $jsess . ',
                                 status  : true, 
                                 cookie  : true, 
                                 xfbml   : true 
                             });

                             // whenever the user logs in, we refresh the page
                             FB.Event.subscribe(\'auth.login\', function() {
                                 window.location.(' . $reloadurl . ');
                             });
                         };

                         (function() {
                             var e = document.createElement(\'script\');
                             e.src = document.location.protocol + \'//connect.facebook.net/en_US/all.js\';
                             e.async = true;
                             document.getElementById(\'fb-root\').appendChild(e);
                         }());
                     </script>';
            $fb .= '<fb:login-button autologoutlink="false" perms="email,read_stream" onlogin="******"></fb:login-button>';
            return $fb;
        }
    }
Ejemplo n.º 16
0
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <!--
      We use the JS SDK to provide a richer user experience. For more info,
      look here: http://github.com/facebook/connect-js
    -->
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '<?php echo $facebook->getAppId(); ?>',
          session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true // parse XFBML
        });

        // whenever the user logs in, we refresh the page
//        FB.Event.subscribe('auth.login', function() {
//          window.location.reload();
//        });
//        FB.login(function(response) {
//          if (response.session) {
//            // user successfully logged in
//            alert("ok");
//          } else {
Ejemplo n.º 17
0
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <!--
      We use the JS SDK to provide a richer user experience. For more info,
      look here: http://github.com/facebook/connect-js
    -->
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId   : '<?php 
echo $facebook->getAppId();
?>
',
          session : <?php 
echo json_encode($session);
?>
, // don't refetch the session when PHP already has it
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true // parse XFBML
        });

        // whenever the user logs in, we refresh the page
        FB.Event.subscribe('auth.sessionChange', function() {
          window.location.reload();
        });
Ejemplo n.º 18
0
 /**
  * This method is called by the LogoutListener when a user has requested
  * to be logged out. Usually, you would unset session variables, or remove
  * cookies, etc.
  *
  * @param Request        $request
  * @param Response       $response
  * @param TokenInterface $token
  * @return void
  */
 public function logout(Request $request, Response $response, TokenInterface $token)
 {
     $fb_cookie = sprintf('fbsr_%d', $this->facebookApi->getAppId());
     $response->headers->clearCookie($fb_cookie);
 }