/**
  * Instantiates a FacebookSession from the signed request from input.
  *
  * @return FacebookSession|null
  */
 public function getSession()
 {
     if ($this->signedRequest && $this->signedRequest->hasOAuthData()) {
         return FacebookSession::newSessionFromSignedRequest($this->signedRequest);
     }
     return null;
 }
Ejemplo n.º 2
0
 public function getUser($id)
 {
     FacebookSession::setDefaultApplication(self::$config['APPID'], self::$config['SECURITY_KEY']);
     $accessToken = \Yii::$app->session->get('USER')->token;
     $session = new FacebookSession($accessToken);
     $currentUser = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
     $user = new SocialUser();
     $user->first_name = $currentUser->asArray()['first_name'];
     $user->last_name = $currentUser->asArray()['last_name'];
     return $user;
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 public function actionFb()
 {
     \yii::$app->session->set('1', 1);
     $fbAPI = \yii::$app->params['fbAPI'];
     FacebookSession::setDefaultApplication($fbAPI['APPID'], $fbAPI['SECURITY_KEY']);
     $helper = new FacebookRedirectLoginHelper($fbAPI['redirectURL']);
     try {
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookRequestException $ex) {
         \yii::$app->response->redirect(\yii::$app->params['loginURL']);
     } catch (\Exception $ex) {
         \yii::$app->response->redirect(\yii::$app->params['loginURL']);
     }
     if (!isset($session)) {
         \yii::$app->response->redirect(\yii::$app->params['loginURL']);
     }
     $currentUser = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
     if (is_null($currentUser->getId())) {
         \yii::$app->response->redirect('/auth');
     }
     $user = User::find()->where(['site' => User::SITE_FB, 'socialid' => $currentUser->getId()])->one();
     if (!$user) {
         $user = new User();
         $user->site = User::SITE_FB;
         $user->status = User::STATUS_SOCIAL_APPROVE;
         $user->socialid = (string) $currentUser->getId();
         $user->token = $session->getAccessToken();
         $isSaved = $user->save();
         if (!$isSaved) {
             throw new Exception('Не удалось сохранить пользователя.');
         }
     } else {
         $user->token = $session->getAccessToken();
         $user->save();
     }
     \yii::$app->session->set('USER', $user);
     \yii::$app->response->redirect('/auth/checktype');
 }
Ejemplo n.º 5
0
 /**
  * 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());
 }
Ejemplo n.º 6
0
 /**
  * Get more info about an access token.
  *
  * @param string|null $appId
  * @param string|null $appSecret
  *
  * @return GraphSessionInfo
  */
 public function getInfo($appId = null, $appSecret = null)
 {
     $params = array('input_token' => $this->accessToken);
     $request = new FacebookRequest(FacebookSession::newAppSession($appId, $appSecret), 'GET', '/debug_token', $params);
     $response = $request->execute()->getGraphObject(GraphSessionInfo::className());
     // Update the data on this token
     if ($response->getExpiresAt()) {
         $this->expiresAt = $response->getExpiresAt();
     }
     return $response;
 }