public function BuildLink($params = null) { require_once 'Facebook/FacebookSDKException.php'; $APP_ID = $this->GetClientId(); $APP_SECRET = $this->GetClientSecret(); if (!isset($APP_ID) || !isset($APP_SECRET)) { throw new \Facebook\FacebookSDKException('You must to set the app client credentials'); } require_once 'Facebook/FacebookSession.php'; \Facebook\FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET); $CALLBACK_URL = $this->GetCallbackUrl(); if (!isset($CALLBACK_URL)) { throw new \Facebook\FacebookSDKException('You must to set callback url'); } $SCOPE = $this->GetScope(); if (!isset($SCOPE)) { throw new \Facebook\FacebookSDKException('You must to set scope'); } require_once 'Facebook/FacebookRequest.php'; require_once 'Facebook/FacebookRedirectLoginHelper.php'; $helper = new \Facebook\FacebookRedirectLoginHelper($CALLBACK_URL); $STATE = $this->GetState(); if (isset($STATE)) { $helper->SetState($STATE); } $redirectUrl = $helper->getLoginUrl($SCOPE); // var_dump($redirectUrl); return $redirectUrl; }
/** * Get the URL to authorize Facebook * * @param string $callback the callback URL * * @return bool|string */ function socialink_facebook_get_authorize_url($callback) { if (empty($callback)) { return false; } if (!socialink_facebook_available()) { return false; } $_SESSION["socialink_facebook"] = array("callback" => $callback); $redirect = new Facebook\FacebookRedirectLoginHelper($callback); $scope = array("offline_access", "publish_stream", "user_about_me", "user_location", "email"); return $redirect->getLoginUrl($scope); }
public function signin() { FacebookSession::setDefaultApplication(Ntentan::$config['social.facebook.app_id'], Ntentan::$config['social.facebook.secret']); $helper = new \Facebook\FacebookRedirectLoginHelper('http://paanoo.com/users/signin/facebook'); try { $session = $helper->getSessionFromRedirect(); if ($session === null) { header('Location: ' . $helper->getLoginUrl(array('email'))); } } catch (FacebookRequestException $ex) { } catch (\Exception $ex) { } if ($session) { try { $userRequest = new FacebookRequest($session, 'GET', '/me'); $user = $userRequest->execute()->getGraphObject(GraphUser::className())->asArray(); return array('firstname' => $user['first_name'], 'lastname' => $user['last_name'], 'key' => "facebook_{$user['id']}", 'avatar' => "http://graph.facebook.com/{$user['id']}/picture?type=large", 'email' => $user['email'], 'email_confirmed' => $user['verified'], 'avatar_format' => 'jpg'); } catch (Exception $ex) { } } }
/** * Getting token wth Grap Api * * @param $scope array * @param $redirectURl string * @return array */ public function getAccessToken($redirectURl, $scope = null) { if ($scope == '') { $scope = $this->allScope; } $helper = new \Facebook\FacebookRedirectLoginHelper($redirectURl); try { $tokenInfo = json_encode(file_get_contents('https://graph.facebook.com/oauth/access_token?' . http_build_query(array('client_id' => APP_ID, 'client_secret' => APP_SECRET, 'redirect_uri' => $redirectURl, 'code' => $_GET['code'])))); $token = explode("=", $tokenInfo); $response['tokenExpireTime'] = $token[2]; $key = explode("&expires", $token[1]); $response['token'] = $key[0]; $session = new \Facebook\FacebookSession($key[0]); $response['logoutURL'] = $helper->getLogoutUrl($session, $redirectURl); $response['status'] = true; return $response; } catch (Exception $e) { $response['exceptionCode'] = $e->getCode(); $response['exceptionMessage'] = $e->getMessage(); $response['loginURL'] = $helper->getLoginUrl($scope); $response['status'] = false; return $response; } }
$crud = new CRUD(); $urlTraduction = ''; $website = $crud->dbQS(1, '_website'); if (!empty($website)) { $langueGroupe = @unserialize($website['langue_groupe']); $cLangue = count($langueGroupe); if ($cLangue) { $urlTraduction = $website['langue_front'] . '/'; } if ($website['oauth_facebook_active'] === '1' && !empty($website['oauth_facebook_id']) && !empty($website['oauth_facebook_secret'])) { $app_id = $website['oauth_facebook_id']; $app_secret = $website['oauth_facebook_secret']; $my_url = BASE_URL . 'oauth2/facebook/connexion/'; \Facebook\FacebookSession::setDefaultApplication($app_id, $app_secret); $helper = new \Facebook\FacebookRedirectLoginHelper($my_url); $loginUrl = $helper->getLoginUrl(); if (isset($_GET['code'])) { $code = $_GET['code']; $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code; $response = @file_get_contents($token_url); $params = null; parse_str($response, $params); $acces_token = $params['access_token']; // If you already have a valid access token: $session = new \Facebook\FacebookSession($acces_token); // To validate the session: try { $user_profile = (new \Facebook\FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(\Facebook\GraphUser::className()); $email = $user_profile->getEmail(); if ($email) { $UserFacebookQuery = new UserFacebookQuery($crud);
/** * アプリ許可URLを取得 * * @param $config * @return string */ public function getLoginUrl($config = array()) { if (isset($config['redirect_uri'])) { $url = $config['redirect_uri']; } else { $url = $this->getRequestUrl(); } $scope = array(); if (isset($config['scope'])) { if (is_array($config['scope'])) { $scope = $config['scope']; } else { if (is_string($config['scope'])) { $scope = explode(',', $config['scope']); } } } $helper = new Facebook\FacebookRedirectLoginHelper($url); $session = $helper->getSessionFromRedirect(); return $helper->getLoginUrl($scope); //return $this->facebook->getLoginUrl($config); }
/** * Method to setup facebook params and redirect to facebook auth URL * * @param object $view view object * @param object $tpl template object * @return void */ public function display($view, $tpl) { // Set up the config for the facebook sdk instance $config = array('appId' => $this->params->get('app_id'), 'secret' => $this->params->get('app_secret'), 'fileUpload' => false); // Set up params for the login call $params = array('scope' => 'public_profile,email', 'display' => 'page', 'redirect_uri' => self::getReturnUrl($view->return)); \Facebook\FacebookSession::setDefaultApplication($config['appId'], $config['secret']); $helper = new \Facebook\FacebookRedirectLoginHelper($params['redirect_uri']); $loginUrl = $helper->getLoginUrl(explode(',', $params['scope'])); // Redirect to the login URL App::redirect($loginUrl); }
$website = $crud->dbQS(Constant::$websiteId, '_website'); if (!empty($website)) { $langueGroupe = @unserialize($website['langue_groupe']); $cLangue = count($langueGroupe); if ($cLangue) { $urlTraduction = $website['langue_front'] . '/'; } if ($website['oauth_facebook_active'] === '1' && !empty($website['oauth_facebook_id']) && !empty($website['oauth_facebook_secret'])) { $app_id = $website['oauth_facebook_id']; $app_secret = $website['oauth_facebook_secret']; $my_url = BASE_URL . 'oauth2/facebook/login/'; $permissions = array('email'); // optional \Facebook\FacebookSession::setDefaultApplication($app_id, $app_secret); $helper = new \Facebook\FacebookRedirectLoginHelper($my_url); $loginUrl = $helper->getLoginUrl($permissions); if (isset($_GET['code'])) { $code = $_GET['code']; $token_url = "https://graph.facebook.com/oauth/access_token?"; $my_url = urlencode($my_url); $query_url = "client_id=" . $app_id . '&redirect_uri=' . $my_url . "&client_secret=" . $app_secret . "&code=" . $code; // $token_url .= $query_url; // $data = array( // 'client_id' => $app_id, // 'redirect_uri' => $my_url, // 'client_secret' => $app_secret, // 'code' => $code, // ); $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&redirect_uri=" . $my_url . "&client_secret=" . $app_secret . "&code=" . $code; $response = file_get_contents($token_url); $params = null;
public function externalSignInUrl() { $helper = new Facebook\FacebookRedirectLoginHelper($this->signInUrl()); return $helper->getLoginUrl(); }