baseApiUri = new Uri('https://graph.facebook.com/'); } } /** * {@inheritdoc} */ public function getAuthorizationEndpoint() { return new Uri('https://www.facebook.com/dialog/oauth'); } /** * {@inheritdoc} */ public function getAccessTokenEndpoint() { return new Uri('https://graph.facebook.com/oauth/access_token'); } /** * {@inheritdoc} */ protected function parseAccessTokenResponse($responseBody) { // Facebook gives us a query string ... Oh wait. JSON is too simple, understand ? parse_str($responseBody, $data); if (null === $data || !is_array($data)) { throw new TokenResponseException('Unable to parse response.'); } elseif (isset($data['error'])) { throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); } $token = new StdOAuth2Token(); $token->setAccessToken($data['access_token']); if (isset($data['expires'])) { $token->setLifeTime($data['expires']); } if (isset($data['refresh_token'])) { $token->setRefreshToken($data['refresh_token']); unset($data['refresh_token']); } unset($data['access_token']); unset($data['expires']); $token->setExtraParams($data); return $token; } public function getDialogUri($dialogPath, array $parameters) { if (!isset($parameters['redirect_uri'])) { throw new Exception("Redirect uri is mandatory for this request"); } $parameters['app_id'] = $this->credentials->getConsumerId(); $baseUrl = self::WWW_URL . 'dialog/' . $dialogPath; $query = http_build_query($parameters); return new Uri($baseUrl . '?' . $query); } }