/** * get FB cookie * @param CookieManagerInterface $cookieManager * @param CookieMetadataFactory $cookieMetadataFactory * @param \BelVG\FacebookFree\Helper\Data $dataHelper */ public function __construct(CookieManagerInterface $cookieManager, CookieMetadataFactory $cookieMetadataFactory, \BelVG\FacebookFree\Helper\Data $dataHelper) { $this->cookieManager = $cookieManager; $this->cookieMetadataFactory = $cookieMetadataFactory; $this->dataHelper = $dataHelper; $cookieName = self::FB_COOKIE_PREFIX . $this->dataHelper->getAppId(); $this->fbCookie = $this->cookieManager->getCookie($cookieName); }
/** * Get Application Token from FB cookie * * @return string * @throws \RuntimeException */ public function getToken() { $app_id = $this->dataHelper->getAppId(); $secret = $this->dataHelper->getAppSecret(); if ($data = $this->cookie->getParsedCookie()) { if (isset($data['code'])) { $url = sprintf(self::FB_REQUEST_URL, $app_id, $secret, $data['code']); $tokenResponse = $this->getFbData($url); parse_str($tokenResponse, $signedRequest); if (isset($signedRequest['access_token'])) { return $signedRequest['access_token']; } throw new \RuntimeException('Access Token not found'); } throw new \RuntimeException('Request code not found'); } else { throw new \RuntimeException('False Signed Request'); } }
/** * Return applicaton Id * @return string */ public function getAppId() { return $this->dataHelper->getAppId(); }