/** * @param $code * @return null * @throws \Facebook\FacebookRequestException * @throws \Facebook\FacebookSDKException */ protected function getAccessToken($code) { $response = (new FacebookRequest(FacebookSession::newAppSession(), 'GET', '/oauth/access_token', ['client_id' => FacebookSession::_getTargetAppId(), 'client_secret' => FacebookSession::_getTargetAppSecret(), 'redirect_uri' => Config::get('auth.providers.facebook.redirect_uri'), 'code' => $code]))->execute()->getResponse(); // Graph v2.3 and greater return objects on the /oauth/access_token endpoint $accessToken = null; if (is_object($response) && isset($response->access_token)) { $accessToken = $response->access_token; } elseif (is_array($response) && isset($response['access_token'])) { $accessToken = $response['access_token']; } return $accessToken; }
/** * @param FacebookSession $session A Facebook API session * @param LoggerInterface $logger A PSR-3 compatible logger */ public function __construct(FacebookSession $session, LoggerInterface $logger = null) { $this->session = $session; $this->logger = $logger ?: new NullLogger(); if (static::instance() === null) { static::setInstance($this); } try { FacebookSession::_getTargetAppSecret(); } catch (FacebookSDKException $f) { // Disable sending app secret proof and warn FacebookSession::enableAppSecretProof(false); trigger_error('You should set a default app id and secret, see the README.md file ' . 'for more information.', E_USER_DEPRECATED); } }
/** * Initialize the helper and process available signed request data. * * @param string|null $appId * @param string|null $appSecret */ public function __construct($appId = null, $appSecret = null) { $this->appId = FacebookSession::_getTargetAppId($appId); $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); $this->instantiateSignedRequest(); }
/** * Generate and return the appsecret_proof value for an access_token * * @param string $token * * @return string */ public function getAppSecretProof($token) { return hash_hmac('sha256', $token, FacebookSession::_getTargetAppSecret()); }
/** * Hashes the signature used in a signed request. * * @param string $encodedData * @param string|null $appSecret * * @return string * * @throws FacebookSDKException */ public static function hashSignature($encodedData, $appSecret = null) { $hashedSig = hash_hmac('sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true); if ($hashedSig) { return $hashedSig; } throw new FacebookSDKException('Unable to hash signature from encoded payload data.', 602); }
/** * Send a request to Graph with an app access token. * * @param string $endpoint * @param array $params * @param string|null $appId * @param string|null $appSecret * * @return \Facebook\FacebookResponse * * @throws FacebookRequestException */ protected static function request($endpoint, array $params, $appId = null, $appSecret = null) { $targetAppId = FacebookSession::_getTargetAppId($appId); $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret); if (!isset($params['client_id'])) { $params['client_id'] = $targetAppId; } if (!isset($params['client_secret'])) { $params['client_secret'] = $targetAppSecret; } // The response for this endpoint is not JSON, so it must be handled // differently, not as a GraphObject. $request = new FacebookRequest(FacebookSession::newAppSession($targetAppId, $targetAppSecret), 'GET', $endpoint, $params); return $request->execute(); }
/** * Constructs a RedirectLoginHelper for a given appId. * * @param string $appId The application id * @param string $appSecret The application secret */ public function __construct($appId = null, $appSecret = null) { $this->appId = FacebookSession::_getTargetAppId($appId); $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); }
public function fbAuthAction() { $this->view->disable(); $params = array('client_id' => FacebookSession::_getTargetAppId($this->config->facebook->appId), 'redirect_uri' => $this->config->facebook->redirect, 'client_secret' => FacebookSession::_getTargetAppSecret($this->config->facebook->secret), 'code' => isset($_GET['code']) ? $_GET['code'] : null); $response = (new FacebookRequest(FacebookSession::newAppSession($this->config->facebook->appId, $this->config->facebook->secret), 'GET', '/oauth/access_token', $params))->execute()->getResponse(); if (isset($response['access_token'])) { $session = new FacebookSession($response['access_token']); } if (isset($session)) { $userSession['access_token'] = $response['access_token']; $request = new FacebookRequest($session, 'GET', '/me'); $response = $request->execute(); // get response $graphObject = $response->getGraphObject(); $email = $graphObject->getProperty('email'); $fbId = $graphObject->getProperty('id'); $verified = $graphObject->getProperty('verified'); $firstName = $graphObject->getProperty('first_name'); $lastName = $graphObject->getProperty('last_name'); $fullName = $graphObject->getProperty('name'); $gender = $graphObject->getProperty('gender'); $profileLink = $graphObject->getProperty('link'); $bday = $graphObject->getProperty('birthday'); $email = $graphObject->getProperty('email'); $city = $graphObject->getProperty('location')->getProperty('name'); if (!isset($email)) { $email = $fbId . '@facebook.com'; } if (isset($bday)) { $bday = date('Y-m-d', strtotime($bday)); } $socialData = array('social_network' => 'Facebook', 'social_id' => $fbId, 'first_name' => $firstName, 'last_name' => $lastName, 'full_name' => $fullName, 'gender' => $gender, 'profile_link' => $profileLink, 'birthday' => $bday, 'email' => $email, 'city' => $city, 'access_token' => $userSession['access_token']); if ($member = Members::findFirstByEmail($email)) { $userSession = get_object_vars($member); if (!($socialProfile = SocialProfiles::findFirstByEmail($email))) { $socialData['member_id'] = $member->id; $this->newSocialProfile($socialData); } } else { $memberId = $this->newMember($socialData); $socialData['id'] = $memberId; $userSession = $socialData; $socialData['member_id'] = $memberId; $this->newSocialProfile($socialData); } //print_r($graphObject); $this->session->set('userSession', $userSession); } return $this->response->redirect(); }