Start to rebrand it as Diaspora
This commit is contained in:
parent
3205f6049b
commit
1238e052ff
2
Main.php
2
Main.php
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace IdnoPlugins\Facebook {
|
||||
namespace IdnoPlugins\Diaspora {
|
||||
|
||||
class Main extends \Idno\Common\Plugin
|
||||
{
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Facebook pages
|
||||
* Diaspora pages
|
||||
*/
|
||||
|
||||
namespace IdnoPlugins\Facebook\Pages {
|
||||
namespace IdnoPlugins\Diaspora\Pages {
|
||||
|
||||
/**
|
||||
* Default class to serve Facebook-related account settings
|
||||
* Default class to serve Diaspora-related account settings
|
||||
*/
|
||||
class Account extends \Idno\Common\Page
|
||||
{
|
||||
@ -15,25 +15,25 @@
|
||||
function getContent()
|
||||
{
|
||||
$this->gatekeeper(); // Logged-in users only
|
||||
if ($facebook = \Idno\Core\site()->plugins()->get('Facebook')) {
|
||||
$login_url = $facebook->getAuthURL();
|
||||
if ($diaspora = \Idno\Core\site()->plugins()->get('Diaspora')) {
|
||||
$login_url = $diaspora->getAuthURL();
|
||||
}
|
||||
$t = \Idno\Core\site()->template();
|
||||
$body = $t->__(array('login_url' => $login_url))->draw('account/facebook');
|
||||
$t->__(array('title' => 'Facebook', 'body' => $body))->drawPage();
|
||||
$body = $t->__(array('login_url' => $login_url))->draw('account/diaspora');
|
||||
$t->__(array('title' => 'Diaspora', 'body' => $body))->drawPage();
|
||||
}
|
||||
|
||||
function postContent() {
|
||||
$this->gatekeeper(); // Logged-in users only
|
||||
if (($this->getInput('remove'))) {
|
||||
$user = \Idno\Core\site()->session()->currentUser();
|
||||
$user->facebook = array();
|
||||
$user->diaspora = array();
|
||||
$user->save();
|
||||
\Idno\Core\site()->session()->addMessage('Your Facebook settings have been removed from your account.');
|
||||
\Idno\Core\site()->session()->addMessage('Your Diaspora settings have been removed from your account.');
|
||||
}
|
||||
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/facebook/');
|
||||
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Facebook pages
|
||||
* Diaspora pages
|
||||
*/
|
||||
|
||||
namespace IdnoPlugins\Facebook\Pages {
|
||||
namespace IdnoPlugins\Diaspora\Pages {
|
||||
|
||||
/**
|
||||
* Default class to serve Facebook settings in administration
|
||||
* Default class to serve Diaspora settings in administration
|
||||
*/
|
||||
class Admin extends \Idno\Common\Page
|
||||
{
|
||||
@ -16,23 +16,23 @@
|
||||
{
|
||||
$this->adminGatekeeper(); // Admins only
|
||||
$t = \Idno\Core\site()->template();
|
||||
$body = $t->draw('admin/facebook');
|
||||
$t->__(array('title' => 'Facebook', 'body' => $body))->drawPage();
|
||||
$body = $t->draw('admin/diaspora');
|
||||
$t->__(array('title' => 'Diaspora', 'body' => $body))->drawPage();
|
||||
}
|
||||
|
||||
function postContent() {
|
||||
$this->adminGatekeeper(); // Admins only
|
||||
$appId = $this->getInput('appId');
|
||||
$secret = $this->getInput('secret');
|
||||
\Idno\Core\site()->config->config['facebook'] = array(
|
||||
\Idno\Core\site()->config->config['diaspora'] = array(
|
||||
'appId' => $appId,
|
||||
'secret' => $secret
|
||||
);
|
||||
\Idno\Core\site()->config()->save();
|
||||
\Idno\Core\site()->session()->addMessage('Your Facebook application details were saved.');
|
||||
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'admin/facebook/');
|
||||
\Idno\Core\site()->session()->addMessage('Your Diaspora application details were saved.');
|
||||
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'admin/diaspora/');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Facebook pages
|
||||
* Diaspora pages
|
||||
*/
|
||||
|
||||
namespace IdnoPlugins\Facebook\Pages {
|
||||
namespace IdnoPlugins\Diaspora\Pages {
|
||||
|
||||
/**
|
||||
* Default class to serve the Facebook callback
|
||||
* Default class to serve the Diaspora callback
|
||||
*/
|
||||
class Callback extends \Idno\Common\Page
|
||||
{
|
||||
@ -15,20 +15,20 @@
|
||||
function getContent()
|
||||
{
|
||||
$this->gatekeeper(); // Logged-in users only
|
||||
if ($facebook = \Idno\Core\site()->plugins()->get('Facebook')) {
|
||||
if ($facebookAPI = $facebook->connect()) {
|
||||
/* @var \IdnoPlugins\Facebook\FacebookAPI $facebookAPI */
|
||||
if ($session = $facebookAPI->getSessionOnLogin()) {
|
||||
if ($diaspora = \Idno\Core\site()->plugins()->get('Diaspora')) {
|
||||
if ($diasporaAPI = $diaspora->connect()) {
|
||||
/* @var \IdnoPlugins\diaspora\diasporaAPI $diasporaAPI */
|
||||
if ($session = $diasporaAPI->getSessionOnLogin()) {
|
||||
$user = \Idno\Core\site()->session()->currentUser();
|
||||
$access_token = $session->getToken();
|
||||
$facebookAPI->setAccessToken($access_token);
|
||||
if ($person = $facebookAPI->api('/me','GET')) {
|
||||
$diasporaAPI->setAccessToken($access_token);
|
||||
if ($person = $diasporaAPI->api('/me','GET')) {
|
||||
$name = $person['response']->getProperty('name');
|
||||
$id = $person['response']->getProperty('id');
|
||||
$user->facebook[$id] = ['id' => $id, 'access_token' => $access_token, 'name' => $name];
|
||||
\Idno\Core\site()->syndication()->registerServiceAccount('facebook', $id, $name);
|
||||
$user->diaspora[$id] = ['id' => $id, 'access_token' => $access_token, 'name' => $name];
|
||||
\Idno\Core\site()->syndication()->registerServiceAccount('diaspora', $id, $name);
|
||||
if (\Idno\Core\site()->config()->multipleSyndicationAccounts()) {
|
||||
if ($companies = $facebookAPI->api('/me/accounts','GET')) {
|
||||
if ($companies = $diasporaAPI->api('/me/accounts','GET')) {
|
||||
if (!empty($companies['response'])) {
|
||||
foreach($companies['response']->asArray() as $company_container) {
|
||||
foreach($company_container as $company) {
|
||||
@ -38,8 +38,8 @@
|
||||
$id = $company['id'];
|
||||
$name = $company['name'];
|
||||
$access_token = $company['access_token'];
|
||||
$user->facebook[$id] = ['id' => $id, 'access_token' => $access_token, 'name' => $name, 'page' => true];
|
||||
\Idno\Core\site()->syndication()->registerServiceAccount('facebook', $id, $name);
|
||||
$user->diaspora[$id] = ['id' => $id, 'access_token' => $access_token, 'name' => $name, 'page' => true];
|
||||
\Idno\Core\site()->syndication()->registerServiceAccount('diaspora', $id, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,7 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$user->facebook = array('access_token' => $access_token);
|
||||
$user->diaspora = array('access_token' => $access_token);
|
||||
}
|
||||
$user->save();
|
||||
}
|
||||
@ -58,9 +58,9 @@
|
||||
unset($_SESSION['onboarding_passthrough']);
|
||||
$this->forward(\Idno\Core\site()->config()->getURL() . 'begin/connect-forwarder');
|
||||
}
|
||||
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/facebook/');
|
||||
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugin administration
|
||||
*/
|
||||
|
||||
namespace IdnoPlugins\Facebook\Pages {
|
||||
|
||||
class Deauth extends \Idno\Common\Page
|
||||
{
|
||||
|
||||
function getContent()
|
||||
{
|
||||
$this->gatekeeper(); // Logged-in users only
|
||||
if ($twitter = \Idno\Core\site()->plugins()->get('Facebook')) {
|
||||
if ($user = \Idno\Core\site()->session()->currentUser()) {
|
||||
if ($account = $this->getInput('remove')) {
|
||||
if (array_key_exists($account, $user->facebook)) {
|
||||
unset($user->facebook[$account]);
|
||||
} else {
|
||||
$user->facebook = false;
|
||||
}
|
||||
}
|
||||
$user->save();
|
||||
\Idno\Core\site()->session()->refreshSessionUser($user);
|
||||
if (!empty($user->link_callback)) {
|
||||
$this->forward($user->link_callback); exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->forward($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
function postContent() {
|
||||
$this->getContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
README.md
11
README.md
@ -1,4 +1,4 @@
|
||||
Facebook for Known
|
||||
Diaspora for Known
|
||||
==================
|
||||
|
||||
This plugin provides POSSE support for Known.
|
||||
@ -6,16 +6,11 @@ This plugin provides POSSE support for Known.
|
||||
Installation
|
||||
------------
|
||||
|
||||
* Drop the Facebook folder into the IdnoPlugins folder of your idno installation.
|
||||
* Drop the Diaspora folder into the IdnoPlugins folder of your idno installation.
|
||||
* Log into Known and click on Administration.
|
||||
* Click "install" next to Facebook.
|
||||
* Click "install" next to Diaspora.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Released under the Apache 2.0 license: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
Contains
|
||||
--------
|
||||
|
||||
Also contains the official PHP Facebook SDK.
|
||||
|
13
external/facebook-sdk/CONTRIBUTING.md
vendored
13
external/facebook-sdk/CONTRIBUTING.md
vendored
@ -1,13 +0,0 @@
|
||||
Contributing
|
||||
------------
|
||||
|
||||
For us to accept contributions you will have to first have signed the
|
||||
[Contributor License Agreement](https://developers.facebook.com/opensource/cla).
|
||||
|
||||
When committing, keep all lines to less than 80 characters, and try to
|
||||
follow the existing style.
|
||||
|
||||
Before creating a pull request, squash your commits into a single commit.
|
||||
|
||||
Add the comments where needed, and provide ample explanation in the
|
||||
commit message.
|
19
external/facebook-sdk/LICENSE
vendored
19
external/facebook-sdk/LICENSE
vendored
@ -1,19 +0,0 @@
|
||||
Copyright 2014 Facebook, Inc.
|
||||
|
||||
You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
use, copy, modify, and distribute this software in source code or binary
|
||||
form for use in connection with the web services and APIs provided by
|
||||
Facebook.
|
||||
|
||||
As with any software that integrates with the Facebook platform, your use
|
||||
of this software is subject to the Facebook Developer Principles and
|
||||
Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
shall be included in all copies or substantial portions of the software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
84
external/facebook-sdk/README.md
vendored
84
external/facebook-sdk/README.md
vendored
@ -1,84 +0,0 @@
|
||||
Facebook SDK for PHP
|
||||
====================
|
||||
|
||||
[![Latest Stable Version](http://img.shields.io/badge/Latest%20Stable-4.0.12-blue.svg)](https://packagist.org/packages/facebook/php-sdk-v4)
|
||||
|
||||
|
||||
This repository contains the open source PHP SDK that allows you to access Facebook
|
||||
Platform from your PHP app.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
This version of the Facebook SDK for PHP requires PHP 5.4 or greater.
|
||||
|
||||
Minimal example:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookSession;
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphUser;
|
||||
use Facebook\FacebookRequestException;
|
||||
|
||||
FacebookSession::setDefaultApplication('YOUR_APP_ID','YOUR_APP_SECRET');
|
||||
|
||||
// Use one of the helper classes to get a FacebookSession object.
|
||||
// FacebookRedirectLoginHelper
|
||||
// FacebookCanvasLoginHelper
|
||||
// FacebookJavaScriptLoginHelper
|
||||
// or create a FacebookSession with a valid access token:
|
||||
$session = new FacebookSession('access-token-here');
|
||||
|
||||
// Get the GraphUser object for the current user:
|
||||
|
||||
try {
|
||||
$me = (new FacebookRequest(
|
||||
$session, 'GET', '/me'
|
||||
))->execute()->getGraphObject(GraphUser::className());
|
||||
echo $me->getName();
|
||||
} catch (FacebookRequestException $e) {
|
||||
// The Graph API returned an error
|
||||
} catch (\Exception $e) {
|
||||
// Some other error occurred
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Complete documentation, installation instructions, and examples are available at:
|
||||
[https://developers.facebook.com/docs/php](https://developers.facebook.com/docs/php)
|
||||
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
||||
1) [Composer](https://getcomposer.org/) is a prerequisite for running the tests.
|
||||
|
||||
Install composer globally, then run `composer install` to install required files.
|
||||
|
||||
2) Create a test app on [Facebook Developers](https://developers.facebook.com), then
|
||||
create `tests/FacebookTestCredentials.php` from `tests/FacebookTestCredentials.php.dist`
|
||||
and edit it to add your credentials.
|
||||
|
||||
3) The tests can be executed by running this command from the root directory:
|
||||
|
||||
```bash
|
||||
./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
For us to accept contributions you will have to first have signed the
|
||||
[Contributor License Agreement](https://developers.facebook.com/opensource/cla).
|
||||
|
||||
When committing, keep all lines to less than 80 characters, and try to
|
||||
follow the existing style.
|
||||
|
||||
Before creating a pull request, squash your commits into a single commit.
|
||||
|
||||
Add the comments where needed, and provide ample explanation in the
|
||||
commit message.
|
70
external/facebook-sdk/autoload.php
vendored
70
external/facebook-sdk/autoload.php
vendored
@ -1,70 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* You only need this file if you are not using composer.
|
||||
* Why are you not using composer?
|
||||
* https://getcomposer.org/
|
||||
*/
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
|
||||
throw new Exception('The Facebook SDK v4 requires PHP version 5.4 or higher.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the autoloader for the Facebook SDK classes.
|
||||
* Based off the official PSR-4 autoloader example found here:
|
||||
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
|
||||
*
|
||||
* @param string $class The fully-qualified class name.
|
||||
* @return void
|
||||
*/
|
||||
spl_autoload_register(function ($class)
|
||||
{
|
||||
// project-specific namespace prefix
|
||||
$prefix = 'Facebook\\';
|
||||
|
||||
// base directory for the namespace prefix
|
||||
$base_dir = defined('FACEBOOK_SDK_V4_SRC_DIR') ? FACEBOOK_SDK_V4_SRC_DIR : __DIR__ . '/src/Facebook/';
|
||||
|
||||
// does the class use the namespace prefix?
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
// no, move to the next registered autoloader
|
||||
return;
|
||||
}
|
||||
|
||||
// get the relative class name
|
||||
$relative_class = substr($class, $len);
|
||||
|
||||
// replace the namespace prefix with the base directory, replace namespace
|
||||
// separators with directory separators in the relative class name, append
|
||||
// with .php
|
||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
// if the file exists, require it
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
30
external/facebook-sdk/composer.json
vendored
30
external/facebook-sdk/composer.json
vendored
@ -1,30 +0,0 @@
|
||||
{
|
||||
"name": "facebook/php-sdk-v4",
|
||||
"description": "Facebook SDK for PHP",
|
||||
"keywords": ["facebook", "sdk"],
|
||||
"type": "library",
|
||||
"homepage": "https://github.com/facebook/facebook-php-sdk-v4",
|
||||
"license": "Facebook Platform",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Facebook",
|
||||
"homepage": "https://github.com/facebook/facebook-php-sdk-v4/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"mockery/mockery": "dev-master",
|
||||
"guzzlehttp/guzzle": "~4.0"
|
||||
},
|
||||
"suggest": {
|
||||
"guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Facebook\\": "src/Facebook/"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<card>
|
||||
# FacebookCanvasLoginHelper for the Facebook SDK for PHP
|
||||
|
||||
A helper class for getting a FacebookSession in a Canvas app
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookCanvasLoginHelper {#overview}
|
||||
|
||||
If your app is loaded through Canvas, Facebook sends a POST request with a signed request. This helper class will handle processing and validating that information with Facebook, and returns a `FacebookSession`.
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
|
||||
$helper = new FacebookCanvasLoginHelper();
|
||||
try {
|
||||
$session = $helper->getSession();
|
||||
} catch (FacebookRequestException $ex) {
|
||||
// When Facebook returns an error
|
||||
} catch (\Exception $ex) {
|
||||
// When validation fails or other local issues
|
||||
}
|
||||
if ($session) {
|
||||
// Logged in.
|
||||
}
|
||||
|
||||
~~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
### getSession {#getsession}
|
||||
`getSession()`
|
||||
Processes the POST request from Facebook, if present. Returns a `FacebookSession` or `null`.
|
||||
</card>
|
@ -1,39 +0,0 @@
|
||||
<card>
|
||||
# FacebookJavaScriptLoginHelper for the Facebook SDK for PHP
|
||||
|
||||
A helper class for getting a FacebookSession using the session from the Facebook SDK for JavaScript.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookJavaScriptLoginHelper {#overview}
|
||||
|
||||
If your web app uses the Facebook SDK for JavaScript, you can access that in your PHP code as well. This helper class will process and validate the cookie data used by the Facebook SDK for JavaScript, returning a `FacebookSession` on success.
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
|
||||
$helper = new FacebookJavaScriptLoginHelper();
|
||||
try {
|
||||
$session = $helper->getSession();
|
||||
} catch(FacebookRequestException $ex) {
|
||||
// When Facebook returns an error
|
||||
} catch(\Exception $ex) {
|
||||
// When validation fails or other local issues
|
||||
}
|
||||
if ($session) {
|
||||
// Logged in.
|
||||
}
|
||||
|
||||
~~~~
|
||||
|
||||
It's important to note that on first access, or if a session has since expired, these methods will operate on data that is one request-cycle stale. You will likely want to make an Ajax request when the login state changes in the Facebook SDK for JavaScript. Information about that here: (FB.event.subscribe)[https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/#events]
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
### getSession {#getsession}
|
||||
`getSession()`
|
||||
Processes the data available from the Facebook SDK for JavaScript, if present. Returns a `FacebookSession` or `null`.
|
||||
</card>
|
@ -1,54 +0,0 @@
|
||||
<card>
|
||||
# FacebookRedirectLoginHelper for the Facebook SDK for PHP
|
||||
|
||||
A helper class for getting a FacebookSession using the OAuth protocol.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookRedirectLoginHelper {#overview}
|
||||
|
||||
If your web app uses Facebook Login on the back-end, you'll need to redirect your visitors to a URL at Facebook to initiate a login request. Facebook then redirects the user to your apps callback URL, providing session data. This helper class will generate the login URL for you, and can process and validate the data from Facebook, returning a `FacebookSession` on success.
|
||||
|
||||
This class can be extended, and the `storeState($state)` and `loadState()` methods overridden, to store the state check using another method besides the default `$_SESSION`.
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
|
||||
$helper = new FacebookRedirectLoginHelper($redirect_url, $appId = NULL, $appSecret = NULL);
|
||||
echo '<a href="' . $helper->getLoginUrl() . '">Login with Facebook</a>';
|
||||
|
||||
~~~~
|
||||
|
||||
Then, in your callback page (at the redirect url) when Facebook sends the user back:
|
||||
|
||||
~~~~
|
||||
|
||||
$helper = new FacebookRedirectLoginHelper($redirect_url);
|
||||
try {
|
||||
$session = $helper->getSessionFromRedirect();
|
||||
} catch(FacebookRequestException $ex) {
|
||||
// When Facebook returns an error
|
||||
} catch(\Exception $ex) {
|
||||
// When validation fails or other local issues
|
||||
}
|
||||
if ($session) {
|
||||
// Logged in.
|
||||
}
|
||||
|
||||
~~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
### getLoginUrl {#getloginurl}
|
||||
`getLoginUrl()`
|
||||
Generates the URL to redirect a web visitor to Facebook to login to your app.
|
||||
### getLogoutUrl {#getlogouturl}
|
||||
`getLogoutUrl($next_url)`
|
||||
Generates the URL to redirect a web visitor to Facebook to logout, with a url to redirect to after.
|
||||
### getSessionFromRedirect {#getsessionfromredirect}
|
||||
`getSessionFromRedirect()`
|
||||
Processes the redirect data from Facebook, if present. Returns a `FacebookSession` or `null`.
|
||||
</card>
|
59
external/facebook-sdk/docs/FacebookRequest.fbmd
vendored
59
external/facebook-sdk/docs/FacebookRequest.fbmd
vendored
@ -1,59 +0,0 @@
|
||||
<card>
|
||||
# FacebookRequest for the Facebook SDK for PHP
|
||||
|
||||
Represents a request that will be made against the Graph API.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookRequest {#overview}
|
||||
|
||||
Constructor:
|
||||
|
||||
~~~~
|
||||
$request = new FacebookRequest(
|
||||
FacebookSession $session,
|
||||
string $httpMethod,
|
||||
string $path,
|
||||
array $params = NULL,
|
||||
string $version = NULL
|
||||
);
|
||||
~~~~
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
// Make a new request and execute it.
|
||||
try {
|
||||
$response = (new FacebookRequest($session, 'GET', '/me'))->execute();
|
||||
$object = $response->getGraphObject();
|
||||
echo $object->getProperty('name');
|
||||
} catch (FacebookRequestException $ex) {
|
||||
echo $ex->getMessage();
|
||||
} catch (\Exception $ex) {
|
||||
echo $ex->getMessage();
|
||||
}
|
||||
|
||||
// You can chain methods together and get a strongly typed GraphUser
|
||||
$me = (new FacebookRequest(
|
||||
$session, 'GET', '/me'
|
||||
))->execute()->getGraphObject(GraphUser::className);
|
||||
echo $me->getName();
|
||||
~~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
### execute {#execute}
|
||||
`execute()`
|
||||
Returns a `Facebook\FacebookResponse` from this request, from which a strongly-typed result can be retrieved. Throws an exception if the request fails. If the error is returned from Facebook, as opposed to a networking issue, a `Facebook\FacebookRequestException` is thrown.
|
||||
### getPath {#getpath}
|
||||
`getPath()`
|
||||
Returns a copy of the path for the request, not including the version.
|
||||
### getParameters {#getparams}
|
||||
`getParameters()`
|
||||
Returns a copy of the parameters array for the request.
|
||||
### getSession {#getsession}
|
||||
`getSession()`
|
||||
Returns the `Facebook\FacebookSession` object associated with this request.
|
||||
</card>
|
@ -1,43 +0,0 @@
|
||||
<card>
|
||||
# FacebookRequestException for the Facebook SDK for PHP
|
||||
|
||||
Represents an exception thrown by executing a Facebook request.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookRequestException {#overview}
|
||||
|
||||
This base class has several subclasses:
|
||||
|
||||
`FacebookAuthorizationException`
|
||||
`FacebookClientException`
|
||||
`FacebookPermissionException`
|
||||
`FacebookServerException`
|
||||
`FacebookThrottleException`
|
||||
`FacebookOtherException`
|
||||
|
||||
Whenever a FacebookRequestException is thrown, it will be one of these types.
|
||||
They are derived from the error information here: https://developers.facebook.com/docs/graph-api/using-graph-api/#errors
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
`FacebookRequestException` extends from the base `\Exception` class, so `getCode()` and `getMessage()` are available by default.
|
||||
|
||||
### getHttpStatusCode {#gethttpstatus}
|
||||
`getHttpStatusCode()`
|
||||
Returns the HTTP status code returned with this exception.
|
||||
### getSubErrorCode {#getsuberrorcode}
|
||||
`getSubErrorCode()`
|
||||
Returns the numeric sub-error code returned from Facebook.
|
||||
### getErrorType {#geterrortype}
|
||||
`getErrorType()`
|
||||
Returns the type of error as a string.
|
||||
### getResponse {#getresponse}
|
||||
`getResponse()`
|
||||
Returns the decoded response used to create the exception.
|
||||
### getRawResponse {#getrawresponse}
|
||||
`getRawResponse()`
|
||||
Returns the raw response used to create the exception.
|
||||
</card>
|
57
external/facebook-sdk/docs/FacebookResponse.fbmd
vendored
57
external/facebook-sdk/docs/FacebookResponse.fbmd
vendored
@ -1,57 +0,0 @@
|
||||
<card>
|
||||
# FacebookResponse for the Facebook SDK for PHP
|
||||
|
||||
Represents a response from the Graph API.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookResponse {#overview}
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
// A FacebookResponse is returned from an executed FacebookRequest
|
||||
try {
|
||||
$response = (new FacebookRequest($session, 'GET', '/me'))->execute();
|
||||
// You can get the request back:
|
||||
$request = $response->getRequest();
|
||||
// You can get the response as a GraphObject:
|
||||
$object = $response->getGraphObject();
|
||||
// You can get the response as a subclass of GraphObject:
|
||||
$me = $response->getGraphObject(GraphUser::className());
|
||||
// If this response has multiple pages, you can get a request for the next or previous pages:
|
||||
$nextPageRequest = $response->getRequestForNextPage();
|
||||
$previousPageRequest = $response->getRequestForPreviousPage();
|
||||
} catch (FacebookRequestException $ex) {
|
||||
echo $ex->getMessage();
|
||||
} catch (\Exception $ex) {
|
||||
echo $ex->getMessage();
|
||||
}
|
||||
|
||||
// You can also chain the methods together:
|
||||
$me = (new FacebookRequest(
|
||||
$session, 'GET', '/me'
|
||||
))->execute()->getGraphObject(GraphUser::className);
|
||||
echo $me->getName();
|
||||
~~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
### getGraphObject {#getgraphobject}
|
||||
`getGraphObject(string $type = 'Facebook\GraphObject')`
|
||||
Returns the result as a `GraphObject`. If specified, a strongly-typed subclass of `GraphObject` is returned.
|
||||
### getGraphObjectList {#getgraphobjectlist}
|
||||
`getGraphObjectList(string $type = 'Facebook\GraphObject')`
|
||||
Returns an array of `GraphObject` returned by this request. If specified, a strongly-typed subclass of `GraphObject` is returned.
|
||||
### getRequest {#getrequest}
|
||||
`getRequest()`
|
||||
Returns the `FacebookRequest` that produced this response.
|
||||
### getRequestForNextPage {#getnextpage}
|
||||
`getRequestForNextPage()`
|
||||
If the response has paginated data, produces a `FacebookRequest` for the next pge of data.
|
||||
### getRequestForPreviousPage {#getpreviouspage}
|
||||
`getRequestForPreviousPage()`
|
||||
If the response has paginated data, produces a `FacebookRequest` for the previous page of data.
|
||||
</card>
|
71
external/facebook-sdk/docs/FacebookSession.fbmd
vendored
71
external/facebook-sdk/docs/FacebookSession.fbmd
vendored
@ -1,71 +0,0 @@
|
||||
<card>
|
||||
# FacebookSession for the Facebook SDK for PHP
|
||||
|
||||
Represents a Facebook Session, which is used when making requests to the Graph API.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\FacebookSession {#overview}
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
use Facebook\FacebookSession;
|
||||
|
||||
FacebookSession::setDefaultApplication('app-id', 'app-secret');
|
||||
|
||||
// If you already have a valid access token:
|
||||
$session = new FacebookSession('access-token');
|
||||
|
||||
// If you're making app-level requests:
|
||||
$session = FacebookSession::newAppSession();
|
||||
|
||||
// To validate the session:
|
||||
try {
|
||||
$session->validate();
|
||||
} catch (FacebookRequestException $ex) {
|
||||
// Session not valid, Graph API returned an exception with the reason.
|
||||
echo $ex->getMessage();
|
||||
} catch (\Exception $ex) {
|
||||
// Graph API returned info, but it may mismatch the current app or have expired.
|
||||
echo $ex->getMessage();
|
||||
}
|
||||
~~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Static Methods {#static-methods}
|
||||
|
||||
### setDefaultApplication {#setdefaultapp}
|
||||
`setDefaultApplication(string $appId, string $appSecret)`
|
||||
Configures and app ID and secret that will be used by default throughout the SDK (but can be overridden whenever necessary using parameters to other methods.
|
||||
### validate {#validate}
|
||||
`validate(Facebook\GraphSessionInfo $sessionInfo, string $appId = NULL, string $appSecret = NULL)`
|
||||
Ensures that the provided GraphSessionInfo is valid, throwing an exception if not. It does this by ensuring the app ID in the token info matches the given (or default) app ID, ensuring the token itself is valid, and ensuring that the expiration time has not passed.
|
||||
### newAppSession {#newappsession}
|
||||
`newAppSession(string $appId = NULL, string $appSecret = NULL)`
|
||||
Returns a `Facebook\FacebookSession` configured with a token for the app which can be used for publishing and for requesting app-level information.
|
||||
### newSessionFromSignedRequest {#newsessionfromsr}
|
||||
`newSessionFromSignedRequest(string $signedRequest)`
|
||||
Returns a `Facebook\FacebookSession` for the given signed request.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Instance Methods {#instance-methods}
|
||||
|
||||
### getToken {#gettoken}
|
||||
`getToken()`
|
||||
Returns the token string for the session.
|
||||
### getSessionInfo {#getsessioninfo}
|
||||
`getSessionInfo(string $appId = NULL, string $appSecret = NULL)`
|
||||
Equivalent to calling the /debug_token endpoint of the Graph API to get the details for the access token for this session. Returns a `Facebook\GraphSessionInfo` object.
|
||||
### getLongLivedSession {#getlonglivedsession}
|
||||
`getLongLivedSession(string $appId = NULL, string $appSecret = NULL)`
|
||||
Returns a new `Facebook\FacebookSession` resulting from extending a short-lived access token. This method will make a network request. If you know you already have a long-lived session, you do not need to call this. The only time you get a short-lived session as of March 2014 is from the Facebook SDK for JavaScript. If this session is not short-lived, this method will return `$this`. A long-lived session is on the order of months. A short-lived session is on the order of hours. You can figure out whether a session is short-lived or long-lived by checking the expiration date in the session info, but it's not a precise thing.
|
||||
### getExchangeToken {#getexchangetoken}
|
||||
`getExchangeToken(string $appId = NULL, string $appSecret = NULL)`
|
||||
Returns an exchange token string which can be sent back to clients and exchanged for a device-linked access token. You need this when your user did not log in on a particular device, but you want to be able to make Graph API calls from that device as this user.
|
||||
### validate {#validatei}
|
||||
`validate(string $appId = NULL, string $appSecret = NULL)`
|
||||
Ensures that a session is valid, throwing an exception if not. It does this by fetching the token info, ensuring the app ID in the token info matches the given (or default) app ID, ensuring the token itself is valid, and ensuring that the expiration time has not passed.
|
||||
</card>
|
155
external/facebook-sdk/docs/GraphObject.fbmd
vendored
155
external/facebook-sdk/docs/GraphObject.fbmd
vendored
@ -1,155 +0,0 @@
|
||||
<card>
|
||||
# GraphObject for the Facebook SDK for PHP
|
||||
|
||||
Represents an object returned by the Graph API.
|
||||
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Facebook\GraphObject {#overview}
|
||||
|
||||
This base class has several subclasses, some are provided by default:
|
||||
|
||||
[__GraphUser__](#user-instance-methods)
|
||||
[__GraphLocation__](#location-instance-methods)
|
||||
[__GraphSessionInfo__](#sessioninfo-instance-methods)
|
||||
|
||||
Usage:
|
||||
|
||||
~~~~
|
||||
// Get the base class GraphObject from the response
|
||||
$object = $response->getGraphObject();
|
||||
|
||||
// Get the response typed as a GraphUser
|
||||
$user = $response->getGraphObject(GraphUser::className());
|
||||
// or convert the base object previously accessed
|
||||
// $user = $object->cast(GraphUser::className());
|
||||
|
||||
// Get the response typed as a GraphLocation
|
||||
$loc = $response->getGraphObject(GraphLocation::className());
|
||||
// or convert the base object previously accessed
|
||||
// $loc = $object->cast(GraphLocation::className());
|
||||
|
||||
// User example
|
||||
echo $object->getProperty('name');
|
||||
echo $user->getName();
|
||||
|
||||
// Location example
|
||||
echo $object->getProperty('country');
|
||||
echo $loc->getCountry();
|
||||
|
||||
// SessionInfo example
|
||||
$info = $session->getSessionInfo());
|
||||
echo $info->getxpiresAt();
|
||||
~~~~
|
||||
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## GraphObject Instance Methods {#instance-methods}
|
||||
|
||||
### cast {#cast}
|
||||
`cast(string $type)`
|
||||
Returns a new instance of a GraphObject subclass with this objects underlying data.
|
||||
|
||||
### asArray {#asarray}
|
||||
`asArray()`
|
||||
Returns the raw representation (associative arrays, nested) of this objects underlying data.
|
||||
|
||||
### getProperty {#getproperty}
|
||||
`getProperty(string $name, string $type = 'Facebook\GraphObject')`
|
||||
Gets the value of a named key for this graph object. If the value is a scalar (string, number, etc.) it will be returned. If it's an associative array, it will be returned as a GraphObject cast to the appropriate subclass type if provided.
|
||||
|
||||
### getPropertyAsArray {#getproparray}
|
||||
`getPropertyAsArray()`
|
||||
Gets the contents of a named array property on this graph object. If the values are scalar (strings, numbers, etc.) they will be returned as-is. If the values are associative arrays, they will be returned as GraphObjects cast to the appropriate subclass type if provided.
|
||||
|
||||
### getPropertyNames
|
||||
`getPropertyNames()`
|
||||
Returns an array with the names of all properties present on this graph object.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## GraphUser Instance Methods {#user-instance-methods}
|
||||
|
||||
### getId {#getid}
|
||||
`getId()`
|
||||
Returns the `id` property for the user as a string if present.
|
||||
### getName {#getname}
|
||||
`getName()`
|
||||
Returns the `name` property for the user as a string if present.
|
||||
### getFirstName {#getfirstname}
|
||||
`getFirstName()`
|
||||
Returns the `first_name` property for the user as a string if present.
|
||||
### getMiddleName {#getmiddlename}
|
||||
`getMiddleName()`
|
||||
Returns the `middle_name` property for the user as a string if present.
|
||||
### getLastName {#getlastname}
|
||||
`getLastName()`
|
||||
Returns the `last_name` property for the user as a string if present.
|
||||
### getLink {#getlink}
|
||||
`getLink()`
|
||||
Returns the `link` property for the user as a string if present.
|
||||
### getUsername {#getusername}
|
||||
`getUsername()`
|
||||
Returns the `username` property for the user as a string if present.
|
||||
### getBirthday {#getbirthday}
|
||||
`getBirthday()`
|
||||
Returns the `birthday` property for the user as a `\DateTime` if present.
|
||||
### getLocation {#getlocation}
|
||||
`getLocation()`
|
||||
Returns the `location` property for the user as a `Facebook\GraphLocation` if present.'
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## GraphLocation Instance Methods {#location-instance-methods}
|
||||
|
||||
### getStreet {#getstreet}
|
||||
`getStreet()`
|
||||
Returns the `street` property for the location as a string if present.
|
||||
### getCity {#getcity}
|
||||
`getCity()`
|
||||
Returns the `city` property for the location as a string if present.
|
||||
### getState {#getstate}
|
||||
`getState()`
|
||||
Returns the `state` property for the location as a string if present.
|
||||
### getCountry {#getcountry}
|
||||
`getCountry()`
|
||||
Returns the `country` property for the location as a string if present.
|
||||
### getZip {#getzip}
|
||||
`getZip()`
|
||||
Returns the `zip` property for the user as a location if present.
|
||||
### getLatitude {#getlat}
|
||||
`getLatitude()`
|
||||
Returns the `latitude` property for the location as a float if present.
|
||||
### getLongitude {#getlon}
|
||||
`getLongitude()`
|
||||
Returns the `latitude` property for the location as a float if present.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## GraphSessionInfo Instance Methods {#sessioninfo-instance-methods}
|
||||
|
||||
### getAppId {#getappid}
|
||||
`getAppId()`
|
||||
Returns the `app_id` property for the session as a string if present.
|
||||
### getApplication {#getapp}
|
||||
`getApplication()`
|
||||
Returns the `application` property for the session as a string if present.
|
||||
### getExpiresAt {#getexpires}
|
||||
`getExpiresAt()`
|
||||
Returns the `expires_at` property for the session as a \DateTime if present.
|
||||
### getIsValid {#getvalid}
|
||||
`getIsValid()`
|
||||
Returns the `is_valid` property for the session as a boolean if present.
|
||||
### getIssuedAt {#getissued}
|
||||
`getIssuedAt()`
|
||||
Returns the `issued_at` property for the session as a \DateTime if present.
|
||||
### getScopes {#getscopes}
|
||||
`getScopes()`
|
||||
Returns the `scopes` property for the session as an array if present.
|
||||
### getId {#getuid}
|
||||
`getId()`
|
||||
Returns the `user_id` property for the session as a string if present.
|
||||
</card>
|
||||
|
44
external/facebook-sdk/docs/post_links.fbmd
vendored
44
external/facebook-sdk/docs/post_links.fbmd
vendored
@ -1,44 +0,0 @@
|
||||
<card>
|
||||
# Post Links Using the Graph API
|
||||
|
||||
This example covers posting a link to the current user's timeline using the Graph API and Facebook SDK for PHP.
|
||||
|
||||
It assumes that you've already set your default app id and secret, and acquired a `FacebookSession` using an access token or one of the login helper classes found [here](/docs/php). You must have requested the `publish_actions` scope when logging in the user for this to work.
|
||||
|
||||
For more information, see the documentation for [`GraphObject`](/docs/php/GraphObject), [`FacebookRequest`](/docs/php/FacebookRequest), and [`FacebookRequestException`](/docs/php/FacebookRequestException).
|
||||
|
||||
</card>
|
||||
|
||||
<card>
|
||||
|
||||
~~~~
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphObject;
|
||||
use Facebook\FacebookRequestException;
|
||||
|
||||
if($session) {
|
||||
|
||||
try {
|
||||
|
||||
$response = (new FacebookRequest(
|
||||
$session, 'POST', '/me/feed', array(
|
||||
'link' => 'www.example.com',
|
||||
'message' => 'User provided message'
|
||||
)
|
||||
))->execute()->getGraphObject();
|
||||
|
||||
echo "Posted with id: " . $response->getProperty('id');
|
||||
|
||||
} catch(FacebookRequestException $e) {
|
||||
|
||||
echo "Exception occured, code: " . $e->getCode();
|
||||
echo " with message: " . $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
~~~~
|
||||
|
||||
Note that the 'message' field must come from the user, as pre-filled content is forbidden by the [Platform Policies](https://developers.intern.facebook.com/policy/#control) (2.3).
|
||||
|
||||
</card>
|
@ -1,38 +0,0 @@
|
||||
<card>
|
||||
# Retrieve User Profile via the Graph API
|
||||
|
||||
This example covers getting profile information for the current user and printing their name, using the Graph API and the Facebook SDK for PHP.
|
||||
|
||||
It assumes that you've already set your default app id and secret, and acquired a `FacebookSession` using an access token or one of the login helper classes found [here](/docs/php).
|
||||
|
||||
For more information, see the documentation for [`GraphObject`](/docs/php/GraphObject), [`GraphUser`](/docs/php/GraphObject/#user-instance-methods), [`FacebookRequest`](/docs/php/FacebookRequest), and [`FacebookRequestException`](/docs/php/FacebookRequestException).
|
||||
|
||||
</card>
|
||||
|
||||
<card>
|
||||
|
||||
~~~~
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphUser;
|
||||
use Facebook\FacebookRequestException;
|
||||
|
||||
if($session) {
|
||||
|
||||
try {
|
||||
|
||||
$user_profile = (new FacebookRequest(
|
||||
$session, 'GET', '/me'
|
||||
))->execute()->getGraphObject(GraphUser::className());
|
||||
|
||||
echo "Name: " . $user_profile->getName();
|
||||
|
||||
} catch(FacebookRequestException $e) {
|
||||
|
||||
echo "Exception occured, code: " . $e->getCode();
|
||||
echo " with message: " . $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
~~~~
|
||||
</card>
|
136
external/facebook-sdk/docs/sdk_getting_started.fbmd
vendored
136
external/facebook-sdk/docs/sdk_getting_started.fbmd
vendored
@ -1,136 +0,0 @@
|
||||
<card>
|
||||
# Getting started with the Facebook SDK for PHP
|
||||
|
||||
The Facebook SDK for PHP provides developers with a modern, native library for accessing the Graph API and taking advantage of Facebook Login. Usually this means you're developing with PHP for a Facebook Canvas app, building your own website, or adding server-side functionality to an app that already uses the [Facebook SDK for JavaScript](/docs/reference/javascript/).
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Download the SDK {#download}
|
||||
|
||||
%FB(devsite:markdown-wiki:info-card {
|
||||
content: "The Facebook SDK for PHP v4 requires PHP 5.4 or greater.",
|
||||
type: 'warning',
|
||||
})
|
||||
|
||||
If you're using [Composer](https://getcomposer.org/) as a package manager for PHP, which we recommend, installing the SDK is as easy as adding a require entry for the Facebook SDK for PHP to the composer.json file in the root of your project:
|
||||
|
||||
~~~~
|
||||
{
|
||||
"require" : {
|
||||
"facebook/php-sdk-v4" : "~4.0.12"
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
|
||||
Then run composer with the install parameter, and it will download the newest version. If you're using the autoloader as part of Composer, the Facebook namespace will be available for use without adding require statements for all of the files.
|
||||
|
||||
If you're not using Composer, you can download the SDK from our GitHub:
|
||||
|
||||
%FB(devsite:markdown-wiki:button {
|
||||
text: 'Download the PHP SDK',
|
||||
href: 'https://github.com/facebook/facebook-php-sdk-v4/archive/4.0-dev.zip',
|
||||
size: 'large',
|
||||
use: 'special',
|
||||
})
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Initializing {#init}
|
||||
|
||||
You will need to have configured a Facebook App, which you can obtain from the [App Dashboard](http://developers.facebook.com/apps).
|
||||
|
||||
Then, initialize the SDK with your app ID and secret:
|
||||
|
||||
~~~
|
||||
session_start(); // For the Facebook SDK to work correctly, you need to start a PHP session
|
||||
FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
|
||||
~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Authentication and authorization {#authentication}
|
||||
|
||||
The SDK can be used to support login your site using a Facebook account. On the server-side, the SDK provides helper classes for the most common scenarios.
|
||||
|
||||
For most websites, you'll use the [FacebookRedirectLoginHelper](/docs/php/FacebookRedirectLoginHelper). Generate the login URL to redirect visitors to with the `getLoginUrl()` method, redirect them, and then process the response from Facebook with the `getSessionFromRedirect()` method, which returns a `FacebookSession`.
|
||||
|
||||
~~~~
|
||||
$helper = new FacebookRedirectLoginHelper('your redirect URL here');
|
||||
$loginUrl = $helper->getLoginUrl();
|
||||
// Use the login url on a link or button to redirect to Facebook for authentication
|
||||
~~~~
|
||||
|
||||
~~~~
|
||||
$helper = new FacebookRedirectLoginHelper();
|
||||
try {
|
||||
$session = $helper->getSessionFromRedirect();
|
||||
} catch(FacebookRequestException $ex) {
|
||||
// When Facebook returns an error
|
||||
} catch(\Exception $ex) {
|
||||
// When validation fails or other local issues
|
||||
}
|
||||
if ($session) {
|
||||
// Logged in
|
||||
}
|
||||
~~~~
|
||||
|
||||
If your app is on Facebook Canvas, use the `getSession()` method on [FacebookCanvasLoginHelper](/docs/php/FacebookCanvasLoginHelper) to get a `FacebookSession` for the user.
|
||||
|
||||
~~~~
|
||||
$helper = new FacebookCanvasLoginHelper();
|
||||
try {
|
||||
$session = $helper->getSession();
|
||||
} catch(FacebookRequestException $ex) {
|
||||
// When Facebook returns an error
|
||||
} catch(\Exception $ex) {
|
||||
// When validation fails or other local issues
|
||||
}
|
||||
if ($session) {
|
||||
// Logged in
|
||||
}
|
||||
~~~~
|
||||
|
||||
If you're already using the Facebook SDK for JavaScript to authenticate users, you can also log them in on the server side with the [FacebookJavaScriptLoginHelper](/docs/php/FacebookJavaScriptLoginHelper). The `getSession()` method will return a `FacebookSession`.
|
||||
|
||||
~~~~
|
||||
$helper = new FacebookJavaScriptLoginHelper();
|
||||
try {
|
||||
$session = $helper->getSession();
|
||||
} catch(FacebookRequestException $ex) {
|
||||
// When Facebook returns an error
|
||||
} catch(\Exception $ex) {
|
||||
// When validation fails or other local issues
|
||||
}
|
||||
if ($session) {
|
||||
// Logged in
|
||||
}
|
||||
~~~~
|
||||
|
||||
You can also create a `FacebookSession` with an access token you've acquired through some other means, by passing it to the constructor.
|
||||
|
||||
~~~~
|
||||
$session = new FacebookSession('access token here');
|
||||
~~~~
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Making Requests to the Graph API {#making-requests}
|
||||
|
||||
Once you have a `FacebookSession` you can begin making calls to the Graph API with [FacebookRequest](/docs/php/FacebookRequest).
|
||||
|
||||
~~~~
|
||||
$request = new FacebookRequest($session, 'GET', '/me');
|
||||
$response = $request->execute();
|
||||
$graphObject = $response->getGraphObject();
|
||||
~~~~
|
||||
|
||||
You can also chain these methods:
|
||||
|
||||
~~~~
|
||||
$me = (new FacebookRequest(
|
||||
$session, 'GET', '/me'
|
||||
))->execute()->getGraphObject(GraphUser::className());
|
||||
~~~~
|
||||
|
||||
For more details, see the examples and API reference for all of these classes listed on the [landing page for the Facebook SDK for PHP](/docs/reference/php).
|
||||
</card>
|
45
external/facebook-sdk/docs/sdk_landing_page.fbmd
vendored
45
external/facebook-sdk/docs/sdk_landing_page.fbmd
vendored
@ -1,45 +0,0 @@
|
||||
<card>
|
||||
# Facebook SDK for PHP
|
||||
|
||||
The Facebook SDK for PHP provides developers with a modern, native library for accessing the Graph API and taking advantage of Facebook Login. Usually this means you're developing with PHP for a Facebook Canvas app, building your own website, or adding server-side functionality to an app that already uses the [Facebook SDK for JavaScript](/docs/reference/javascript/).
|
||||
|
||||
Take a look through our guide, [Getting Started with the Facebook SDK for PHP](/docs/php/gettingstarted), and then check out some of the examples below.
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## Examples {#examples}
|
||||
|
||||
* [Retrieve a users profile](/docs/php/howto/profilewithgraphapi)
|
||||
* [Post a link to a users feed](/docs/php/howto/postwithgraphapi)
|
||||
* [Upload a photo to a users profile](/docs/php/howto/uploadphoto)
|
||||
|
||||
</card>
|
||||
|
||||
<card>
|
||||
## API Reference - Facebook namespace {#reference}
|
||||
|
||||
[Facebook\FacebookSession](/docs/php/FacebookSession)
|
||||
An access token backed session used when making requests against the Graph API.
|
||||
|
||||
[Facebook\FacebookRequest](/docs/php/FacebookRequest)
|
||||
Makes requests against the Graph API.
|
||||
|
||||
[Facebook\FacebookResponse](/docs/php/FacebookResponse)
|
||||
A successful response from the Graph API resulting from a FacebookRequest.
|
||||
|
||||
[Facebook\FacebookRequestException](/docs/php/FacebookRequestException)
|
||||
An error returned by the Graph API during a FacebookRequest. Subclasses: FacebookClientException, FacebookServerException, FacebookAuthorizationException, FacebookPermissionException, FacebookThrottleException, FacebookOtherException.
|
||||
|
||||
[Facebook\GraphObject](/docs/php/GraphObject)
|
||||
Represents an object returned by the Graph API. Subclasses: GraphUser, GraphLocation, GraphSessionInfo
|
||||
|
||||
[Facebook\FacebookRedirectLoginHelper](/docs/php/FacebookRedirectLoginHelper)
|
||||
A helper class for getting a FacebookSession using the OAuth protocol.
|
||||
|
||||
[Facebook\FacebookCanvasLoginHelper](/docs/php/FacebookCanvasLoginHelper)
|
||||
A helper class for getting a FacebookSession from Facebook Canvas.
|
||||
|
||||
[Facebook\FacebookJavaScriptLoginHelper](/docs/php/FacebookJavaScriptLoginHelper)
|
||||
A helper class for getting a FacebookSession from the Facebook SDK for JavaScript.
|
||||
|
||||
</card>
|
49
external/facebook-sdk/docs/upload_photo.fbmd
vendored
49
external/facebook-sdk/docs/upload_photo.fbmd
vendored
@ -1,49 +0,0 @@
|
||||
<card>
|
||||
# Upload Photos to a User's Profile
|
||||
|
||||
This example covers uploading a photo to the current User's profile using the Graph API and the Facebook SDK for PHP.
|
||||
|
||||
It assumes that you've already set your default app id and secret, and acquired a `FacebookSession` using an access token or one of the login helper classes found [here](/docs/php). You must have requested the `publish_actions` scope when logging in the user for this to work.
|
||||
|
||||
For more information, see the documentation for [`GraphObject`](/docs/php/GraphObject), [`FacebookRequest`](/docs/php/FacebookRequest), and [`FacebookRequestException`](/docs/php/FacebookRequestException).
|
||||
|
||||
</card>
|
||||
|
||||
<card>
|
||||
|
||||
~~~~
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphObject;
|
||||
use Facebook\FacebookRequestException;
|
||||
|
||||
if($session) {
|
||||
|
||||
try {
|
||||
|
||||
// Upload to a user's profile. The photo will be in the
|
||||
// first album in the profile. You can also upload to
|
||||
// a specific album by using /ALBUM_ID as the path
|
||||
$response = (new FacebookRequest(
|
||||
$session, 'POST', '/me/photos', array(
|
||||
'source' => new CURLFile('path/to/file.name', 'image/png'),
|
||||
'message' => 'User provided message'
|
||||
)
|
||||
))->execute()->getGraphObject();
|
||||
|
||||
// If you're not using PHP 5.5 or later, change the file reference to:
|
||||
// 'source' => '@/path/to/file.name'
|
||||
|
||||
echo "Posted with id: " . $response->getProperty('id');
|
||||
|
||||
} catch(FacebookRequestException $e) {
|
||||
|
||||
echo "Exception occured, code: " . $e->getCode();
|
||||
echo " with message: " . $e->getMessage();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
~~~~
|
||||
|
||||
Note that the 'message' field must come from the user, as pre-filled content is forbidden by the [Platform Policies](https://developers.intern.facebook.com/policy/#control) (2.3).
|
||||
</card>
|
19
external/facebook-sdk/phpunit.xml.dist
vendored
19
external/facebook-sdk/phpunit.xml.dist
vendored
@ -1,19 +0,0 @@
|
||||
<phpunit
|
||||
colors="true"
|
||||
stderr="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
stopOnFailure="false"
|
||||
bootstrap="tests/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Facebook PHP SDK v4 Test Suite">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./src/Facebook</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -1,370 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\Entities;
|
||||
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\FacebookRequestException;
|
||||
use Facebook\FacebookSession;
|
||||
use Facebook\GraphSessionInfo;
|
||||
|
||||
/**
|
||||
* Class AccessToken
|
||||
* @package Facebook
|
||||
*/
|
||||
class AccessToken
|
||||
{
|
||||
|
||||
/**
|
||||
* The access token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $accessToken;
|
||||
|
||||
/**
|
||||
* A unique ID to identify a client.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $machineId;
|
||||
|
||||
/**
|
||||
* Date when token expires.
|
||||
*
|
||||
* @var \DateTime|null
|
||||
*/
|
||||
protected $expiresAt;
|
||||
|
||||
/**
|
||||
* Create a new access token entity.
|
||||
*
|
||||
* @param string $accessToken
|
||||
* @param int $expiresAt
|
||||
* @param string|null machineId
|
||||
*/
|
||||
public function __construct($accessToken, $expiresAt = 0, $machineId = null)
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
if ($expiresAt) {
|
||||
$this->setExpiresAtFromTimeStamp($expiresAt);
|
||||
}
|
||||
$this->machineId = $machineId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for expires_at.
|
||||
*
|
||||
* @param int $timeStamp
|
||||
*/
|
||||
protected function setExpiresAtFromTimeStamp($timeStamp)
|
||||
{
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($timeStamp);
|
||||
$this->expiresAt = $dt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for expiresAt.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getExpiresAt()
|
||||
{
|
||||
return $this->expiresAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for machineId.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMachineId()
|
||||
{
|
||||
return $this->machineId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this is a long-lived token.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLongLived()
|
||||
{
|
||||
if ($this->expiresAt) {
|
||||
return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the validity of the access token.
|
||||
*
|
||||
* @param string|null $appId Application ID to use
|
||||
* @param string|null $appSecret App secret value to use
|
||||
* @param string|null $machineId
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($appId = null, $appSecret = null, $machineId = null)
|
||||
{
|
||||
$accessTokenInfo = $this->getInfo($appId, $appSecret);
|
||||
$machineId = $machineId ?: $this->machineId;
|
||||
return static::validateAccessToken($accessTokenInfo, $appId, $machineId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the provided GraphSessionInfo object is valid,
|
||||
* throwing an exception if not. Ensures the appId matches,
|
||||
* that the machineId matches if it's being used,
|
||||
* that the token is valid and has not expired.
|
||||
*
|
||||
* @param GraphSessionInfo $tokenInfo
|
||||
* @param string|null $appId Application ID to use
|
||||
* @param string|null $machineId
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function validateAccessToken(GraphSessionInfo $tokenInfo,
|
||||
$appId = null, $machineId = null)
|
||||
{
|
||||
$targetAppId = FacebookSession::_getTargetAppId($appId);
|
||||
|
||||
$appIdIsValid = $tokenInfo->getAppId() == $targetAppId;
|
||||
$machineIdIsValid = $tokenInfo->getProperty('machine_id') == $machineId;
|
||||
$accessTokenIsValid = $tokenInfo->isValid();
|
||||
|
||||
// Not all access tokens return an expiration. E.g. an app access token.
|
||||
if ($tokenInfo->getExpiresAt() instanceof \DateTime) {
|
||||
$accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time();
|
||||
} else {
|
||||
$accessTokenIsStillAlive = true;
|
||||
}
|
||||
|
||||
return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a valid access token from a code.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
* @param string|null $machineId
|
||||
*
|
||||
* @return AccessToken
|
||||
*/
|
||||
public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null)
|
||||
{
|
||||
$params = array(
|
||||
'code' => $code,
|
||||
'redirect_uri' => '',
|
||||
);
|
||||
|
||||
if ($machineId) {
|
||||
$params['machine_id'] = $machineId;
|
||||
}
|
||||
|
||||
return static::requestAccessToken($params, $appId, $appSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a valid code from an access token.
|
||||
*
|
||||
* @param AccessToken|string $accessToken
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return AccessToken
|
||||
*/
|
||||
public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null)
|
||||
{
|
||||
$accessToken = (string) $accessToken;
|
||||
|
||||
$params = array(
|
||||
'access_token' => $accessToken,
|
||||
'redirect_uri' => '',
|
||||
);
|
||||
|
||||
return static::requestCode($params, $appId, $appSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchanges a short lived access token with a long lived access token.
|
||||
*
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return AccessToken
|
||||
*/
|
||||
public function extend($appId = null, $appSecret = null)
|
||||
{
|
||||
$params = array(
|
||||
'grant_type' => 'fb_exchange_token',
|
||||
'fb_exchange_token' => $this->accessToken,
|
||||
);
|
||||
|
||||
return static::requestAccessToken($params, $appId, $appSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request an access token based on a set of params.
|
||||
*
|
||||
* @param array $params
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return AccessToken
|
||||
*
|
||||
* @throws FacebookRequestException
|
||||
*/
|
||||
public static function requestAccessToken(array $params, $appId = null, $appSecret = null)
|
||||
{
|
||||
$response = static::request('/oauth/access_token', $params, $appId, $appSecret);
|
||||
$data = $response->getResponse();
|
||||
|
||||
/**
|
||||
* @TODO fix this malarkey - getResponse() should always return an object
|
||||
* @see https://github.com/facebook/facebook-php-sdk-v4/issues/36
|
||||
*/
|
||||
if (is_array($data)) {
|
||||
if (isset($data['access_token'])) {
|
||||
$expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0;
|
||||
return new static($data['access_token'], $expiresAt);
|
||||
}
|
||||
} elseif($data instanceof \stdClass) {
|
||||
if (isset($data->access_token)) {
|
||||
$expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0;
|
||||
$machineId = isset($data->machine_id) ? (string) $data->machine_id : null;
|
||||
return new static((string) $data->access_token, $expiresAt, $machineId);
|
||||
}
|
||||
}
|
||||
|
||||
throw FacebookRequestException::create(
|
||||
$response->getRawResponse(),
|
||||
$data,
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a code from a long lived access token.
|
||||
*
|
||||
* @param array $params
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FacebookRequestException
|
||||
*/
|
||||
public static function requestCode(array $params, $appId = null, $appSecret = null)
|
||||
{
|
||||
$response = static::request('/oauth/client_code', $params, $appId, $appSecret);
|
||||
$data = $response->getResponse();
|
||||
|
||||
if (isset($data->code)) {
|
||||
return (string) $data->code;
|
||||
}
|
||||
|
||||
throw FacebookRequestException::create(
|
||||
$response->getRawResponse(),
|
||||
$data,
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the access token as a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
}
|
@ -1,386 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\Entities;
|
||||
|
||||
use Facebook\FacebookSDKException;
|
||||
use Facebook\FacebookSession;
|
||||
|
||||
/**
|
||||
* Class SignedRequest
|
||||
* @package Facebook
|
||||
*/
|
||||
class SignedRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $rawSignedRequest;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $payload;
|
||||
|
||||
/**
|
||||
* Instantiate a new SignedRequest entity.
|
||||
*
|
||||
* @param string|null $rawSignedRequest The raw signed request.
|
||||
* @param string|null $state random string to prevent CSRF.
|
||||
* @param string|null $appSecret
|
||||
*/
|
||||
public function __construct($rawSignedRequest = null, $state = null, $appSecret = null)
|
||||
{
|
||||
if (!$rawSignedRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->rawSignedRequest = $rawSignedRequest;
|
||||
$this->payload = static::parse($rawSignedRequest, $state, $appSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw signed request data.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawSignedRequest()
|
||||
{
|
||||
return $this->rawSignedRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parsed signed request data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getPayload()
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a property from the signed request data if available.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed|null $default
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->payload[$key])) {
|
||||
return $this->payload[$key];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user_id from signed request data if available.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->get('user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for OAuth data in the payload.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasOAuthData()
|
||||
{
|
||||
return isset($this->payload['oauth_token']) || isset($this->payload['code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a signed request from an array of data.
|
||||
*
|
||||
* @param array $payload
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function make(array $payload, $appSecret = null)
|
||||
{
|
||||
$payload['algorithm'] = 'HMAC-SHA256';
|
||||
$payload['issued_at'] = time();
|
||||
$encodedPayload = static::base64UrlEncode(json_encode($payload));
|
||||
|
||||
$hashedSig = static::hashSignature($encodedPayload, $appSecret);
|
||||
$encodedSig = static::base64UrlEncode($hashedSig);
|
||||
|
||||
return $encodedSig.'.'.$encodedPayload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and decodes a signed request and returns
|
||||
* the payload as an array.
|
||||
*
|
||||
* @param string $signedRequest
|
||||
* @param string|null $state
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function parse($signedRequest, $state = null, $appSecret = null)
|
||||
{
|
||||
list($encodedSig, $encodedPayload) = static::split($signedRequest);
|
||||
|
||||
// Signature validation
|
||||
$sig = static::decodeSignature($encodedSig);
|
||||
$hashedSig = static::hashSignature($encodedPayload, $appSecret);
|
||||
static::validateSignature($hashedSig, $sig);
|
||||
|
||||
// Payload validation
|
||||
$data = static::decodePayload($encodedPayload);
|
||||
static::validateAlgorithm($data);
|
||||
if ($state) {
|
||||
static::validateCsrf($data, $state);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the format of a signed request.
|
||||
*
|
||||
* @param string $signedRequest
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function validateFormat($signedRequest)
|
||||
{
|
||||
if (strpos($signedRequest, '.') !== false) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Malformed signed request.', 606
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a raw valid signed request.
|
||||
*
|
||||
* @param string $signedRequest
|
||||
*
|
||||
* @returns array
|
||||
*/
|
||||
public static function split($signedRequest)
|
||||
{
|
||||
static::validateFormat($signedRequest);
|
||||
|
||||
return explode('.', $signedRequest, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the raw signature from a signed request.
|
||||
*
|
||||
* @param string $encodedSig
|
||||
*
|
||||
* @returns string
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function decodeSignature($encodedSig)
|
||||
{
|
||||
$sig = static::base64UrlDecode($encodedSig);
|
||||
|
||||
if ($sig) {
|
||||
return $sig;
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Signed request has malformed encoded signature data.', 607
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the raw payload from a signed request.
|
||||
*
|
||||
* @param string $encodedPayload
|
||||
*
|
||||
* @returns array
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function decodePayload($encodedPayload)
|
||||
{
|
||||
$payload = static::base64UrlDecode($encodedPayload);
|
||||
|
||||
if ($payload) {
|
||||
$payload = json_decode($payload, true);
|
||||
}
|
||||
|
||||
if (is_array($payload)) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Signed request has malformed encoded payload data.', 607
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the algorithm used in a signed request.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function validateAlgorithm(array $data)
|
||||
{
|
||||
if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Signed request is using the wrong algorithm.', 605
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the signature used in a signed request.
|
||||
*
|
||||
* @param string $hashedSig
|
||||
* @param string $sig
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function validateSignature($hashedSig, $sig)
|
||||
{
|
||||
if (mb_strlen($hashedSig) === mb_strlen($sig)) {
|
||||
$validate = 0;
|
||||
for ($i = 0; $i < mb_strlen($sig); $i++) {
|
||||
$validate |= ord($hashedSig[$i]) ^ ord($sig[$i]);
|
||||
}
|
||||
if ($validate === 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Signed request has an invalid signature.', 602
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a signed request against CSRF.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $state
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function validateCsrf(array $data, $state)
|
||||
{
|
||||
if (isset($data['state']) && $data['state'] === $state) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Signed request did not pass CSRF validation.', 604
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 decoding which replaces characters:
|
||||
* + instead of -
|
||||
* / instead of _
|
||||
* @link http://en.wikipedia.org/wiki/Base64#URL_applications
|
||||
*
|
||||
* @param string $input base64 url encoded input
|
||||
*
|
||||
* @return string decoded string
|
||||
*/
|
||||
public static function base64UrlDecode($input)
|
||||
{
|
||||
$urlDecodedBase64 = strtr($input, '-_', '+/');
|
||||
static::validateBase64($urlDecodedBase64);
|
||||
return base64_decode($urlDecodedBase64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 encoding which replaces characters:
|
||||
* + instead of -
|
||||
* / instead of _
|
||||
* @link http://en.wikipedia.org/wiki/Base64#URL_applications
|
||||
*
|
||||
* @param string $input string to encode
|
||||
*
|
||||
* @return string base64 url encoded input
|
||||
*/
|
||||
public static function base64UrlEncode($input)
|
||||
{
|
||||
return strtr(base64_encode($input), '+/', '-_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a base64 string.
|
||||
*
|
||||
* @param string $input base64 value to validate
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function validateBase64($input)
|
||||
{
|
||||
$pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/';
|
||||
if (preg_match($pattern, $input)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FacebookSDKException(
|
||||
'Signed request contains malformed base64 encoding.', 608
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookAuthorizationException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookAuthorizationException extends FacebookRequestException
|
||||
{
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookCanvasLoginHelper
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookCanvasLoginHelper extends FacebookSignedRequestFromInputHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the app data value.
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getAppData()
|
||||
{
|
||||
return $this->signedRequest ? $this->signedRequest->get('app_data') : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw signed request from POST.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawSignedRequest()
|
||||
{
|
||||
$rawSignedRequest = $this->getRawSignedRequestFromPost();
|
||||
if ($rawSignedRequest) {
|
||||
return $rawSignedRequest;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookClientException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookClientException extends FacebookRequestException
|
||||
{
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookJavaScriptLoginHelper
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookJavaScriptLoginHelper extends FacebookSignedRequestFromInputHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Get raw signed request from the cookie.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawSignedRequest()
|
||||
{
|
||||
return $this->getRawSignedRequestFromCookie();
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookOtherException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookOtherException extends FacebookRequestException
|
||||
{
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookPageTabHelper
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
*/
|
||||
class FacebookPageTabHelper extends FacebookCanvasLoginHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected $pageData;
|
||||
|
||||
/**
|
||||
* Initialize the helper and process available signed request data.
|
||||
*
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*/
|
||||
public function __construct($appId = null, $appSecret = null)
|
||||
{
|
||||
parent::__construct($appId, $appSecret);
|
||||
|
||||
if (!$this->signedRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->pageData = $this->signedRequest->get('page');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value from the page data.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed|null $default
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getPageData($key, $default = null)
|
||||
{
|
||||
if (isset($this->pageData[$key])) {
|
||||
return $this->pageData[$key];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the page is liked by the user.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLiked()
|
||||
{
|
||||
return $this->getPageData('liked') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user is an admin.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->getPageData('admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page id if available.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPageId()
|
||||
{
|
||||
return $this->getPageData('id');
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookPermissionException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookPermissionException extends FacebookRequestException
|
||||
{
|
||||
|
||||
}
|
@ -1,307 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookRedirectLoginHelper
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookRedirectLoginHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string The application id
|
||||
*/
|
||||
private $appId;
|
||||
|
||||
/**
|
||||
* @var string The application secret
|
||||
*/
|
||||
private $appSecret;
|
||||
|
||||
/**
|
||||
* @var string The redirect URL for the application
|
||||
*/
|
||||
private $redirectUrl;
|
||||
|
||||
/**
|
||||
* @var string Prefix to use for session variables
|
||||
*/
|
||||
private $sessionPrefix = 'FBRLH_';
|
||||
|
||||
/**
|
||||
* @var string State token for CSRF validation
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* @var boolean Toggle for PHP session status check
|
||||
*/
|
||||
protected $checkForSessionStatus = true;
|
||||
|
||||
/**
|
||||
* Constructs a RedirectLoginHelper for a given appId and redirectUrl.
|
||||
*
|
||||
* @param string $redirectUrl The URL Facebook should redirect users to
|
||||
* after login
|
||||
* @param string $appId The application id
|
||||
* @param string $appSecret The application secret
|
||||
*/
|
||||
public function __construct($redirectUrl, $appId = null, $appSecret = null)
|
||||
{
|
||||
$this->appId = FacebookSession::_getTargetAppId($appId);
|
||||
$this->appSecret = FacebookSession::_getTargetAppSecret($appSecret);
|
||||
$this->redirectUrl = $redirectUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores CSRF state and returns a URL to which the user should be sent to
|
||||
* in order to continue the login process with Facebook. The
|
||||
* provided redirectUrl should invoke the handleRedirect method.
|
||||
*
|
||||
* @param array $scope List of permissions to request during login
|
||||
* @param string $version Optional Graph API version if not default (v2.0)
|
||||
* @param boolean $displayAsPopup Indicate if the page will be displayed as a popup
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false)
|
||||
{
|
||||
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
|
||||
$this->state = $this->random(16);
|
||||
$this->storeState($this->state);
|
||||
$params = array(
|
||||
'client_id' => $this->appId,
|
||||
'redirect_uri' => $this->redirectUrl,
|
||||
'state' => $this->state,
|
||||
'sdk' => 'php-sdk-' . FacebookRequest::VERSION,
|
||||
'scope' => implode(',', $scope)
|
||||
);
|
||||
|
||||
if ($displayAsPopup)
|
||||
{
|
||||
$params['display'] = 'popup';
|
||||
}
|
||||
|
||||
return 'https://www.facebook.com/' . $version . '/dialog/oauth?' .
|
||||
http_build_query($params, null, '&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL to which the user should be sent to re-request permissions.
|
||||
*
|
||||
* @param array $scope List of permissions to re-request
|
||||
* @param string $version Optional Graph API version if not default (v2.0)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReRequestUrl($scope = array(), $version = null)
|
||||
{
|
||||
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
|
||||
$params = array(
|
||||
'client_id' => $this->appId,
|
||||
'redirect_uri' => $this->redirectUrl,
|
||||
'sdk' => 'php-sdk-' . FacebookRequest::VERSION,
|
||||
'auth_type' => 'rerequest',
|
||||
'scope' => implode(',', $scope)
|
||||
);
|
||||
return 'https://www.facebook.com/' . $version . '/dialog/oauth?' .
|
||||
http_build_query($params, null, '&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to send the user in order to log out of Facebook.
|
||||
*
|
||||
* @param FacebookSession $session The session that will be logged out
|
||||
* @param string $next The url Facebook should redirect the user to after
|
||||
* a successful logout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLogoutUrl(FacebookSession $session, $next)
|
||||
{
|
||||
$params = array(
|
||||
'next' => $next,
|
||||
'access_token' => $session->getToken()
|
||||
);
|
||||
return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a response from Facebook, including a CSRF check, and returns a
|
||||
* FacebookSession.
|
||||
*
|
||||
* @return FacebookSession|null
|
||||
*/
|
||||
public function getSessionFromRedirect()
|
||||
{
|
||||
$this->loadState();
|
||||
if ($this->isValidRedirect()) {
|
||||
$params = array(
|
||||
'client_id' => FacebookSession::_getTargetAppId($this->appId),
|
||||
'redirect_uri' => $this->redirectUrl,
|
||||
'client_secret' =>
|
||||
FacebookSession::_getTargetAppSecret($this->appSecret),
|
||||
'code' => $this->getCode()
|
||||
);
|
||||
$response = (new FacebookRequest(
|
||||
FacebookSession::newAppSession($this->appId, $this->appSecret),
|
||||
'GET',
|
||||
'/oauth/access_token',
|
||||
$params
|
||||
))->execute()->getResponse();
|
||||
if (isset($response['access_token'])) {
|
||||
return new FacebookSession($response['access_token']);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a redirect has a valid state.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isValidRedirect()
|
||||
{
|
||||
return $this->getCode() && isset($_GET['state'])
|
||||
&& $_GET['state'] == $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the code.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getCode()
|
||||
{
|
||||
return isset($_GET['code']) ? $_GET['code'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a state string in session storage for CSRF protection.
|
||||
* Developers should subclass and override this method if they want to store
|
||||
* this state in a different location.
|
||||
*
|
||||
* @param string $state
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
protected function storeState($state)
|
||||
{
|
||||
if ($this->checkForSessionStatus === true
|
||||
&& session_status() !== PHP_SESSION_ACTIVE) {
|
||||
throw new FacebookSDKException(
|
||||
'Session not active, could not store state.', 720
|
||||
);
|
||||
}
|
||||
$_SESSION[$this->sessionPrefix . 'state'] = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a state string from session storage for CSRF validation. May return
|
||||
* null if no object exists. Developers should subclass and override this
|
||||
* method if they want to load the state from a different location.
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
protected function loadState()
|
||||
{
|
||||
if ($this->checkForSessionStatus === true
|
||||
&& session_status() !== PHP_SESSION_ACTIVE) {
|
||||
throw new FacebookSDKException(
|
||||
'Session not active, could not load state.', 721
|
||||
);
|
||||
}
|
||||
if (isset($_SESSION[$this->sessionPrefix . 'state'])) {
|
||||
$this->state = $_SESSION[$this->sessionPrefix . 'state'];
|
||||
return $this->state;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a cryptographically secure pseudrandom number
|
||||
*
|
||||
* @param integer $bytes - number of bytes to return
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*
|
||||
* @todo Support Windows platforms
|
||||
*/
|
||||
public function random($bytes)
|
||||
{
|
||||
if (!is_numeric($bytes)) {
|
||||
throw new FacebookSDKException(
|
||||
"random() expects an integer"
|
||||
);
|
||||
}
|
||||
if ($bytes < 1) {
|
||||
throw new FacebookSDKException(
|
||||
"random() expects an integer greater than zero"
|
||||
);
|
||||
}
|
||||
$buf = '';
|
||||
// http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
|
||||
if (!ini_get('open_basedir')
|
||||
&& is_readable('/dev/urandom')) {
|
||||
$fp = fopen('/dev/urandom', 'rb');
|
||||
if ($fp !== FALSE) {
|
||||
$buf = fread($fp, $bytes);
|
||||
fclose($fp);
|
||||
if($buf !== FALSE) {
|
||||
return bin2hex($buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('mcrypt_create_iv')) {
|
||||
$buf = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
|
||||
if ($buf !== FALSE) {
|
||||
return bin2hex($buf);
|
||||
}
|
||||
}
|
||||
|
||||
while (strlen($buf) < $bytes) {
|
||||
$buf .= md5(uniqid(mt_rand(), true), true);
|
||||
// We are appending raw binary
|
||||
}
|
||||
return bin2hex(substr($buf, 0, $bytes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the session_status() check when using $_SESSION
|
||||
*/
|
||||
public function disableSessionStatusCheck()
|
||||
{
|
||||
$this->checkForSessionStatus = false;
|
||||
}
|
||||
|
||||
}
|
@ -1,313 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
use Facebook\HttpClients\FacebookHttpable;
|
||||
use Facebook\HttpClients\FacebookCurlHttpClient;
|
||||
use Facebook\HttpClients\FacebookStreamHttpClient;
|
||||
|
||||
/**
|
||||
* Class FacebookRequest
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* @const string Version number of the Facebook PHP SDK.
|
||||
*/
|
||||
const VERSION = '4.0.12';
|
||||
|
||||
/**
|
||||
* @const string Default Graph API version for requests
|
||||
*/
|
||||
const GRAPH_API_VERSION = 'v2.2';
|
||||
|
||||
/**
|
||||
* @const string Graph API URL
|
||||
*/
|
||||
const BASE_GRAPH_URL = 'https://graph.facebook.com';
|
||||
|
||||
/**
|
||||
* @var FacebookSession The session used for this request
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @var string The HTTP method for the request
|
||||
*/
|
||||
private $method;
|
||||
|
||||
/**
|
||||
* @var string The path for the request
|
||||
*/
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* @var array The parameters for the request
|
||||
*/
|
||||
private $params;
|
||||
|
||||
/**
|
||||
* @var string The Graph API version for the request
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* @var string ETag sent with the request
|
||||
*/
|
||||
private $etag;
|
||||
|
||||
/**
|
||||
* @var FacebookHttpable HTTP client handler
|
||||
*/
|
||||
private static $httpClientHandler;
|
||||
|
||||
/**
|
||||
* @var int The number of calls that have been made to Graph.
|
||||
*/
|
||||
public static $requestCount = 0;
|
||||
|
||||
/**
|
||||
* getSession - Returns the associated FacebookSession.
|
||||
*
|
||||
* @return FacebookSession
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPath - Returns the associated path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* getParameters - Returns the associated parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* getMethod - Returns the associated method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* getETag - Returns the ETag sent with the request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getETag()
|
||||
{
|
||||
return $this->etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* setHttpClientHandler - Returns an instance of the HTTP client
|
||||
* handler
|
||||
*
|
||||
* @param \Facebook\HttpClients\FacebookHttpable
|
||||
*/
|
||||
public static function setHttpClientHandler(FacebookHttpable $handler)
|
||||
{
|
||||
static::$httpClientHandler = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* getHttpClientHandler - Returns an instance of the HTTP client
|
||||
* data handler
|
||||
*
|
||||
* @return FacebookHttpable
|
||||
*/
|
||||
public static function getHttpClientHandler()
|
||||
{
|
||||
if (static::$httpClientHandler) {
|
||||
return static::$httpClientHandler;
|
||||
}
|
||||
return function_exists('curl_init') ? new FacebookCurlHttpClient() : new FacebookStreamHttpClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* FacebookRequest - Returns a new request using the given session. optional
|
||||
* parameters hash will be sent with the request. This object is
|
||||
* immutable.
|
||||
*
|
||||
* @param FacebookSession $session
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param array|null $parameters
|
||||
* @param string|null $version
|
||||
* @param string|null $etag
|
||||
*/
|
||||
public function __construct(
|
||||
FacebookSession $session, $method, $path, $parameters = null, $version = null, $etag = null
|
||||
)
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->method = $method;
|
||||
$this->path = $path;
|
||||
if ($version) {
|
||||
$this->version = $version;
|
||||
} else {
|
||||
$this->version = static::GRAPH_API_VERSION;
|
||||
}
|
||||
$this->etag = $etag;
|
||||
|
||||
$params = ($parameters ?: array());
|
||||
if ($session
|
||||
&& !isset($params["access_token"])) {
|
||||
$params["access_token"] = $session->getToken();
|
||||
}
|
||||
if (FacebookSession::useAppSecretProof()
|
||||
&& !isset($params["appsecret_proof"])) {
|
||||
$params["appsecret_proof"] = $this->getAppSecretProof(
|
||||
$params["access_token"]
|
||||
);
|
||||
}
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base Graph URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getRequestURL()
|
||||
{
|
||||
return static::BASE_GRAPH_URL . '/' . $this->version . $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* execute - Makes the request to Facebook and returns the result.
|
||||
*
|
||||
* @return FacebookResponse
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
* @throws FacebookRequestException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$url = $this->getRequestURL();
|
||||
$params = $this->getParameters();
|
||||
|
||||
if ($this->method === "GET") {
|
||||
$url = self::appendParamsToUrl($url, $params);
|
||||
$params = array();
|
||||
}
|
||||
|
||||
$connection = self::getHttpClientHandler();
|
||||
$connection->addRequestHeader('User-Agent', 'fb-php-' . self::VERSION);
|
||||
$connection->addRequestHeader('Accept-Encoding', '*'); // Support all available encodings.
|
||||
|
||||
// ETag
|
||||
if (isset($this->etag)) {
|
||||
$connection->addRequestHeader('If-None-Match', $this->etag);
|
||||
}
|
||||
|
||||
// Should throw `FacebookSDKException` exception on HTTP client error.
|
||||
// Don't catch to allow it to bubble up.
|
||||
$result = $connection->send($url, $this->method, $params);
|
||||
|
||||
static::$requestCount++;
|
||||
|
||||
$etagHit = 304 == $connection->getResponseHttpStatusCode();
|
||||
|
||||
$headers = $connection->getResponseHeaders();
|
||||
$etagReceived = isset($headers['ETag']) ? $headers['ETag'] : null;
|
||||
|
||||
$decodedResult = json_decode($result);
|
||||
if ($decodedResult === null) {
|
||||
$out = array();
|
||||
parse_str($result, $out);
|
||||
return new FacebookResponse($this, $out, $result, $etagHit, $etagReceived);
|
||||
}
|
||||
if (isset($decodedResult->error)) {
|
||||
throw FacebookRequestException::create(
|
||||
$result,
|
||||
$decodedResult->error,
|
||||
$connection->getResponseHttpStatusCode()
|
||||
);
|
||||
}
|
||||
|
||||
return new FacebookResponse($this, $decodedResult, $result, $etagHit, $etagReceived);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* appendParamsToUrl - Gracefully appends params to the URL.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function appendParamsToUrl($url, $params = array())
|
||||
{
|
||||
if (!$params) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
if (strpos($url, '?') === false) {
|
||||
return $url . '?' . http_build_query($params, null, '&');
|
||||
}
|
||||
|
||||
list($path, $query_string) = explode('?', $url, 2);
|
||||
parse_str($query_string, $query_array);
|
||||
|
||||
// Favor params from the original URL over $params
|
||||
$params = array_merge($params, $query_array);
|
||||
|
||||
return $path . '?' . http_build_query($params, null, '&');
|
||||
}
|
||||
|
||||
}
|
@ -1,222 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookRequestException
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookRequestException extends FacebookSDKException
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int Status code for the response causing the exception
|
||||
*/
|
||||
private $statusCode;
|
||||
|
||||
/**
|
||||
* @var string Raw response
|
||||
*/
|
||||
private $rawResponse;
|
||||
|
||||
/**
|
||||
* @var array Decoded response
|
||||
*/
|
||||
private $responseData;
|
||||
|
||||
/**
|
||||
* Creates a FacebookRequestException.
|
||||
*
|
||||
* @param string $rawResponse The raw response from the Graph API
|
||||
* @param array $responseData The decoded response from the Graph API
|
||||
* @param int $statusCode
|
||||
*/
|
||||
public function __construct($rawResponse, $responseData, $statusCode)
|
||||
{
|
||||
$this->rawResponse = $rawResponse;
|
||||
$this->statusCode = $statusCode;
|
||||
$this->responseData = self::convertToArray($responseData);
|
||||
parent::__construct(
|
||||
$this->get('message', 'Unknown Exception'), $this->get('code', -1), null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an error payload from the Graph API and return the appropriate
|
||||
* exception subclass.
|
||||
*
|
||||
* @param string $raw the raw response from the Graph API
|
||||
* @param array $data the decoded response from the Graph API
|
||||
* @param int $statusCode the HTTP response code
|
||||
*
|
||||
* @return FacebookRequestException
|
||||
*/
|
||||
public static function create($raw, $data, $statusCode)
|
||||
{
|
||||
$data = self::convertToArray($data);
|
||||
if (!isset($data['error']['code']) && isset($data['code'])) {
|
||||
$data = array('error' => $data);
|
||||
}
|
||||
$code = (isset($data['error']['code']) ? $data['error']['code'] : null);
|
||||
|
||||
if (isset($data['error']['error_subcode'])) {
|
||||
switch ($data['error']['error_subcode']) {
|
||||
// Other authentication issues
|
||||
case 458:
|
||||
case 459:
|
||||
case 460:
|
||||
case 463:
|
||||
case 464:
|
||||
case 467:
|
||||
return new FacebookAuthorizationException($raw, $data, $statusCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($code) {
|
||||
// Login status or token expired, revoked, or invalid
|
||||
case 100:
|
||||
case 102:
|
||||
case 190:
|
||||
return new FacebookAuthorizationException($raw, $data, $statusCode);
|
||||
break;
|
||||
|
||||
// Server issue, possible downtime
|
||||
case 1:
|
||||
case 2:
|
||||
return new FacebookServerException($raw, $data, $statusCode);
|
||||
break;
|
||||
|
||||
// API Throttling
|
||||
case 4:
|
||||
case 17:
|
||||
case 341:
|
||||
return new FacebookThrottleException($raw, $data, $statusCode);
|
||||
break;
|
||||
|
||||
// Duplicate Post
|
||||
case 506:
|
||||
return new FacebookClientException($raw, $data, $statusCode);
|
||||
break;
|
||||
}
|
||||
|
||||
// Missing Permissions
|
||||
if ($code == 10 || ($code >= 200 && $code <= 299)) {
|
||||
return new FacebookPermissionException($raw, $data, $statusCode);
|
||||
}
|
||||
|
||||
// OAuth authentication error
|
||||
if (isset($data['error']['type'])
|
||||
and $data['error']['type'] === 'OAuthException') {
|
||||
return new FacebookAuthorizationException($raw, $data, $statusCode);
|
||||
}
|
||||
|
||||
// All others
|
||||
return new FacebookOtherException($raw, $data, $statusCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks isset and returns that or a default value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->responseData['error'][$key])) {
|
||||
return $this->responseData['error'][$key];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP status code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttpStatusCode()
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sub-error code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSubErrorCode()
|
||||
{
|
||||
return $this->get('error_subcode', -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorType()
|
||||
{
|
||||
return $this->get('type', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw response used to create the exception.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawResponse()
|
||||
{
|
||||
return $this->rawResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the decoded response used to create the exception.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->responseData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a stdClass object to an array
|
||||
*
|
||||
* @param mixed $object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function convertToArray($object)
|
||||
{
|
||||
if ($object instanceof \stdClass) {
|
||||
return get_object_vars($object);
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
@ -1,206 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookResponse
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookResponse
|
||||
{
|
||||
|
||||
/**
|
||||
* @var FacebookRequest The request which produced this response
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var array The decoded response from the Graph API
|
||||
*/
|
||||
private $responseData;
|
||||
|
||||
/**
|
||||
* @var string The raw response from the Graph API
|
||||
*/
|
||||
private $rawResponse;
|
||||
|
||||
/**
|
||||
* @var bool Indicates whether sent ETag matched the one on the FB side
|
||||
*/
|
||||
private $etagHit;
|
||||
|
||||
/**
|
||||
* @var string ETag received with the response. `null` in case of ETag hit.
|
||||
*/
|
||||
private $etag;
|
||||
|
||||
/**
|
||||
* Creates a FacebookResponse object for a given request and response.
|
||||
*
|
||||
* @param FacebookRequest $request
|
||||
* @param array $responseData JSON Decoded response data
|
||||
* @param string $rawResponse Raw string response
|
||||
* @param bool $etagHit Indicates whether sent ETag matched the one on the FB side
|
||||
* @param string|null $etag ETag received with the response. `null` in case of ETag hit.
|
||||
*/
|
||||
public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->responseData = $responseData;
|
||||
$this->rawResponse = $rawResponse;
|
||||
$this->etagHit = $etagHit;
|
||||
$this->etag = $etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request which produced this response.
|
||||
*
|
||||
* @return FacebookRequest
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the decoded response data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->responseData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawResponse()
|
||||
{
|
||||
return $this->rawResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if ETag matched the one sent with a request
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isETagHit()
|
||||
{
|
||||
return $this->etagHit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ETag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getETag()
|
||||
{
|
||||
return $this->etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the result as a GraphObject. If a type is specified, returns the
|
||||
* strongly-typed subclass of GraphObject for the data.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGraphObject($type = 'Facebook\GraphObject') {
|
||||
return (new GraphObject($this->responseData))->cast($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of GraphObject returned by the request. If a type is
|
||||
* specified, returns the strongly-typed subclass of GraphObject for the data.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGraphObjectList($type = 'Facebook\GraphObject') {
|
||||
$out = array();
|
||||
$data = $this->responseData->data;
|
||||
$dataLength = count($data);
|
||||
for ($i = 0; $i < $dataLength; $i++) {
|
||||
$out[] = (new GraphObject($data[$i]))->cast($type);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this response has paginated data, returns the FacebookRequest for the
|
||||
* next page, or null.
|
||||
*
|
||||
* @return FacebookRequest|null
|
||||
*/
|
||||
public function getRequestForNextPage()
|
||||
{
|
||||
return $this->handlePagination('next');
|
||||
}
|
||||
|
||||
/**
|
||||
* If this response has paginated data, returns the FacebookRequest for the
|
||||
* previous page, or null.
|
||||
*
|
||||
* @return FacebookRequest|null
|
||||
*/
|
||||
public function getRequestForPreviousPage()
|
||||
{
|
||||
return $this->handlePagination('previous');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the FacebookRequest for the previous or next page, or null.
|
||||
*
|
||||
* @param string $direction
|
||||
*
|
||||
* @return FacebookRequest|null
|
||||
*/
|
||||
private function handlePagination($direction) {
|
||||
if (isset($this->responseData->paging->$direction)) {
|
||||
$url = parse_url($this->responseData->paging->$direction);
|
||||
parse_str($url['query'], $params);
|
||||
|
||||
if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){
|
||||
unset($params['type']);
|
||||
}
|
||||
return new FacebookRequest(
|
||||
$this->request->getSession(),
|
||||
$this->request->getMethod(),
|
||||
$this->request->getPath(),
|
||||
$params
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookSDKException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookSDKException extends \Exception
|
||||
{
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookServerException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookServerException extends FacebookRequestException
|
||||
{
|
||||
|
||||
}
|
@ -1,367 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
use Facebook\Entities\AccessToken;
|
||||
use Facebook\Entities\SignedRequest;
|
||||
|
||||
/**
|
||||
* Class FacebookSession
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class FacebookSession
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultAppId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultAppSecret;
|
||||
|
||||
/**
|
||||
* @var AccessToken The AccessToken entity for this connection.
|
||||
*/
|
||||
private $accessToken;
|
||||
|
||||
/**
|
||||
* @var SignedRequest
|
||||
*/
|
||||
private $signedRequest;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected static $useAppSecretProof = true;
|
||||
|
||||
/**
|
||||
* When creating a Session from an access_token, use:
|
||||
* var $session = new FacebookSession($accessToken);
|
||||
* This will validate the token and provide a Session object ready for use.
|
||||
* It will throw a SessionException in case of error.
|
||||
*
|
||||
* @param AccessToken|string $accessToken
|
||||
* @param SignedRequest $signedRequest The SignedRequest entity
|
||||
*/
|
||||
public function __construct($accessToken, SignedRequest $signedRequest = null)
|
||||
{
|
||||
$this->accessToken = $accessToken instanceof AccessToken ? $accessToken : new AccessToken($accessToken);
|
||||
$this->signedRequest = $signedRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the access token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return (string) $this->accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the access token entity.
|
||||
*
|
||||
* @return AccessToken
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SignedRequest entity.
|
||||
*
|
||||
* @return SignedRequest
|
||||
*/
|
||||
public function getSignedRequest()
|
||||
{
|
||||
return $this->signedRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the signed request payload.
|
||||
*
|
||||
* @return null|array
|
||||
*/
|
||||
public function getSignedRequestData()
|
||||
{
|
||||
return $this->signedRequest ? $this->signedRequest->getPayload() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a property from the signed request data if available.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
public function getSignedRequestProperty($key)
|
||||
{
|
||||
return $this->signedRequest ? $this->signedRequest->get($key) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user_id from signed request data if available.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->signedRequest ? $this->signedRequest->getUserId() : null;
|
||||
}
|
||||
|
||||
// @TODO Remove getSessionInfo() in 4.1: can be accessed from AccessToken directly
|
||||
/**
|
||||
* getSessionInfo - Makes a request to /debug_token with the appropriate
|
||||
* arguments to get debug information about the sessions token.
|
||||
*
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return GraphSessionInfo
|
||||
*/
|
||||
public function getSessionInfo($appId = null, $appSecret = null)
|
||||
{
|
||||
return $this->accessToken->getInfo($appId, $appSecret);
|
||||
}
|
||||
|
||||
// @TODO Remove getLongLivedSession() in 4.1: can be accessed from AccessToken directly
|
||||
/**
|
||||
* getLongLivedSession - Returns a new Facebook session resulting from
|
||||
* extending a short-lived access token. If this session is not
|
||||
* short-lived, returns $this.
|
||||
*
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return FacebookSession
|
||||
*/
|
||||
public function getLongLivedSession($appId = null, $appSecret = null)
|
||||
{
|
||||
$longLivedAccessToken = $this->accessToken->extend($appId, $appSecret);
|
||||
return new static($longLivedAccessToken, $this->signedRequest);
|
||||
}
|
||||
|
||||
// @TODO Remove getExchangeToken() in 4.1: can be accessed from AccessToken directly
|
||||
/**
|
||||
* getExchangeToken - Returns an exchange token string which can be sent
|
||||
* back to clients and exchanged for a device-linked access token.
|
||||
*
|
||||
* @param string|null $appId
|
||||
* @param string|null $appSecret
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExchangeToken($appId = null, $appSecret = null)
|
||||
{
|
||||
return AccessToken::getCodeFromAccessToken($this->accessToken, $appId, $appSecret);
|
||||
}
|
||||
|
||||
// @TODO Remove validate() in 4.1: can be accessed from AccessToken directly
|
||||
/**
|
||||
* validate - Ensures the current session is valid, throwing an exception if
|
||||
* not. Fetches token info from Facebook.
|
||||
*
|
||||
* @param string|null $appId Application ID to use
|
||||
* @param string|null $appSecret App secret value to use
|
||||
* @param string|null $machineId
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public function validate($appId = null, $appSecret = null, $machineId = null)
|
||||
{
|
||||
if ($this->accessToken->isValid($appId, $appSecret, $machineId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @TODO For v4.1 this should not throw an exception, but just return false.
|
||||
throw new FacebookSDKException(
|
||||
'Session has expired, or is not valid for this app.', 601
|
||||
);
|
||||
}
|
||||
|
||||
// @TODO Remove validateSessionInfo() in 4.1: can be accessed from AccessToken directly
|
||||
/**
|
||||
* validateTokenInfo - Ensures the provided GraphSessionInfo object is valid,
|
||||
* throwing an exception if not. Ensures the appId matches,
|
||||
* that the token is valid and has not expired.
|
||||
*
|
||||
* @param GraphSessionInfo $tokenInfo
|
||||
* @param string|null $appId Application ID to use
|
||||
* @param string|null $machineId
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function validateSessionInfo(GraphSessionInfo $tokenInfo,
|
||||
$appId = null,
|
||||
$machineId = null)
|
||||
{
|
||||
if (AccessToken::validateAccessToken($tokenInfo, $appId, $machineId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @TODO For v4.1 this should not throw an exception, but just return false.
|
||||
throw new FacebookSDKException(
|
||||
'Session has expired, or is not valid for this app.', 601
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* newSessionFromSignedRequest - Returns a FacebookSession for a
|
||||
* given signed request.
|
||||
*
|
||||
* @param SignedRequest $signedRequest
|
||||
*
|
||||
* @return FacebookSession
|
||||
*/
|
||||
public static function newSessionFromSignedRequest(SignedRequest $signedRequest)
|
||||
{
|
||||
if ($signedRequest->get('code')
|
||||
&& !$signedRequest->get('oauth_token')) {
|
||||
return self::newSessionAfterValidation($signedRequest);
|
||||
}
|
||||
$accessToken = $signedRequest->get('oauth_token');
|
||||
$expiresAt = $signedRequest->get('expires', 0);
|
||||
$accessToken = new AccessToken($accessToken, $expiresAt);
|
||||
return new static($accessToken, $signedRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* newSessionAfterValidation - Returns a FacebookSession for a
|
||||
* validated & parsed signed request.
|
||||
*
|
||||
* @param SignedRequest $signedRequest
|
||||
*
|
||||
* @return FacebookSession
|
||||
*/
|
||||
protected static function newSessionAfterValidation(SignedRequest $signedRequest)
|
||||
{
|
||||
$code = $signedRequest->get('code');
|
||||
$accessToken = AccessToken::getAccessTokenFromCode($code);
|
||||
return new static($accessToken, $signedRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* newAppSession - Returns a FacebookSession configured with a token for the
|
||||
* application which can be used for publishing and requesting app-level
|
||||
* information.
|
||||
*
|
||||
* @param string|null $appId Application ID to use
|
||||
* @param string|null $appSecret App secret value to use
|
||||
*
|
||||
* @return FacebookSession
|
||||
*/
|
||||
public static function newAppSession($appId = null, $appSecret = null)
|
||||
{
|
||||
$targetAppId = static::_getTargetAppId($appId);
|
||||
$targetAppSecret = static::_getTargetAppSecret($appSecret);
|
||||
return new FacebookSession(
|
||||
$targetAppId . '|' . $targetAppSecret
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefaultApplication - Will set the static default appId and appSecret
|
||||
* to be used for API requests.
|
||||
*
|
||||
* @param string $appId Application ID to use by default
|
||||
* @param string $appSecret App secret value to use by default
|
||||
*/
|
||||
public static function setDefaultApplication($appId, $appSecret)
|
||||
{
|
||||
self::$defaultAppId = $appId;
|
||||
self::$defaultAppSecret = $appSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* _getTargetAppId - Will return either the provided app Id or the default,
|
||||
* throwing if neither are populated.
|
||||
*
|
||||
* @param string $appId
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function _getTargetAppId($appId = null) {
|
||||
$target = ($appId ?: self::$defaultAppId);
|
||||
if (!$target) {
|
||||
throw new FacebookSDKException(
|
||||
'You must provide or set a default application id.', 700
|
||||
);
|
||||
}
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* _getTargetAppSecret - Will return either the provided app secret or the
|
||||
* default, throwing if neither are populated.
|
||||
*
|
||||
* @param string $appSecret
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public static function _getTargetAppSecret($appSecret = null) {
|
||||
$target = ($appSecret ?: self::$defaultAppSecret);
|
||||
if (!$target) {
|
||||
throw new FacebookSDKException(
|
||||
'You must provide or set a default application secret.', 701
|
||||
);
|
||||
}
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable sending the appsecret_proof with requests.
|
||||
*
|
||||
* @param bool $on
|
||||
*/
|
||||
public static function enableAppSecretProof($on = true)
|
||||
{
|
||||
static::$useAppSecretProof = ($on ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not appsecret_proof should be sent with requests.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function useAppSecretProof()
|
||||
{
|
||||
return static::$useAppSecretProof;
|
||||
}
|
||||
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
use Facebook\Entities\SignedRequest;
|
||||
|
||||
/**
|
||||
* Class FacebookSignedRequestFromInputHelper
|
||||
* @package Facebook
|
||||
*/
|
||||
abstract class FacebookSignedRequestFromInputHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Facebook\Entities\SignedRequest|null
|
||||
*/
|
||||
protected $signedRequest;
|
||||
|
||||
/**
|
||||
* @var string the app id
|
||||
*/
|
||||
protected $appId;
|
||||
|
||||
/**
|
||||
* @var string the app secret
|
||||
*/
|
||||
protected $appSecret;
|
||||
|
||||
/**
|
||||
* @var string|null Random string to prevent CSRF.
|
||||
*/
|
||||
public $state = null;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new SignedRequest entity.
|
||||
*
|
||||
* @param string|null
|
||||
*/
|
||||
public function instantiateSignedRequest($rawSignedRequest = null)
|
||||
{
|
||||
$rawSignedRequest = $rawSignedRequest ?: $this->getRawSignedRequest();
|
||||
|
||||
if (!$rawSignedRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->signedRequest = new SignedRequest($rawSignedRequest, $this->state, $this->appSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SignedRequest entity.
|
||||
*
|
||||
* @return \Facebook\Entities\SignedRequest|null
|
||||
*/
|
||||
public function getSignedRequest()
|
||||
{
|
||||
return $this->signedRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user_id if available.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->signedRequest ? $this->signedRequest->getUserId() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw signed request from input.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
abstract public function getRawSignedRequest();
|
||||
|
||||
/**
|
||||
* Get raw signed request from GET input.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawSignedRequestFromGet()
|
||||
{
|
||||
if (isset($_GET['signed_request'])) {
|
||||
return $_GET['signed_request'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw signed request from POST input.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawSignedRequestFromPost()
|
||||
{
|
||||
if (isset($_POST['signed_request'])) {
|
||||
return $_POST['signed_request'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw signed request from cookie set from the Javascript SDK.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRawSignedRequestFromCookie()
|
||||
{
|
||||
if (isset($_COOKIE['fbsr_' . $this->appId])) {
|
||||
return $_COOKIE['fbsr_' . $this->appId];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class FacebookThrottleException
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookThrottleException extends FacebookRequestException
|
||||
{
|
||||
|
||||
}
|
173
external/facebook-sdk/src/Facebook/GraphAlbum.php
vendored
173
external/facebook-sdk/src/Facebook/GraphAlbum.php
vendored
@ -1,173 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphAlbum
|
||||
* @package Facebook
|
||||
* @author Daniele Grosso <daniele.grosso@gmail.com>
|
||||
*/
|
||||
|
||||
class GraphAlbum extends GraphObject
|
||||
{
|
||||
/**
|
||||
* Returns the ID for the album.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getProperty('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the viewer can upload photos to this album.
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function canUpload()
|
||||
{
|
||||
return $this->getProperty('can_upload');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of photos in this album.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return$this->getProperty('count');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the album's cover photo.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCoverPhoto()
|
||||
{
|
||||
return$this->getProperty('cover_photo');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time the album was initially created.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getCreatedTime()
|
||||
{
|
||||
$value = $this->getProperty('created_time');
|
||||
if ($value) {
|
||||
return new \DateTime($value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time the album was updated.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getUpdatedTime()
|
||||
{
|
||||
$value = $this->getProperty('updated_time');
|
||||
if ($value) {
|
||||
return new \DateTime($value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the album.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return$this->getProperty('description');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns profile that created the album.
|
||||
*
|
||||
* @return GraphUser|null
|
||||
*/
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->getProperty('from', GraphUser::className());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link to this album on Facebook.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLink()
|
||||
{
|
||||
return$this->getProperty('link');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the textual location of the album.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLocation()
|
||||
{
|
||||
return$this->getProperty('location');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title of the album.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return$this->getProperty('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the privacy settings for the album.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPrivacy()
|
||||
{
|
||||
return$this->getProperty('privacy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the album. enum{profile, mobile, wall, normal, album}
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return$this->getProperty('type');
|
||||
}
|
||||
|
||||
//TODO: public function getPlace() that should return GraphPage
|
||||
}
|
105
external/facebook-sdk/src/Facebook/GraphLocation.php
vendored
105
external/facebook-sdk/src/Facebook/GraphLocation.php
vendored
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphLocation
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class GraphLocation extends GraphObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the street component of the location
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStreet()
|
||||
{
|
||||
return $this->getProperty('street');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the city component of the location
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCity()
|
||||
{
|
||||
return $this->getProperty('city');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state component of the location
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->getProperty('state');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the country component of the location
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCountry()
|
||||
{
|
||||
return $this->getProperty('country');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the zipcode component of the location
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getZip()
|
||||
{
|
||||
return $this->getProperty('zip');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the latitude component of the location
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function getLatitude()
|
||||
{
|
||||
return $this->getProperty('latitude');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the street component of the location
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function getLongitude()
|
||||
{
|
||||
return $this->getProperty('longitude');
|
||||
}
|
||||
|
||||
}
|
171
external/facebook-sdk/src/Facebook/GraphObject.php
vendored
171
external/facebook-sdk/src/Facebook/GraphObject.php
vendored
@ -1,171 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphObject
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class GraphObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array - Holds the raw associative data for this object
|
||||
*/
|
||||
protected $backingData;
|
||||
|
||||
/**
|
||||
* Creates a GraphObject using the data provided.
|
||||
*
|
||||
* @param array $raw
|
||||
*/
|
||||
public function __construct($raw)
|
||||
{
|
||||
if ($raw instanceof \stdClass) {
|
||||
$raw = get_object_vars($raw);
|
||||
}
|
||||
$this->backingData = $raw;
|
||||
|
||||
if (isset($this->backingData['data']) && count($this->backingData) === 1) {
|
||||
if ($this->backingData['data'] instanceof \stdClass) {
|
||||
$this->backingData = get_object_vars($this->backingData['data']);
|
||||
} else {
|
||||
$this->backingData = $this->backingData['data'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cast - Return a new instance of a FacebookGraphObject subclass for this
|
||||
* objects underlying data.
|
||||
*
|
||||
* @param string $type The GraphObject subclass to cast to
|
||||
*
|
||||
* @return GraphObject
|
||||
*
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public function cast($type)
|
||||
{
|
||||
if ($this instanceof $type) {
|
||||
return $this;
|
||||
}
|
||||
if (is_subclass_of($type, GraphObject::className())) {
|
||||
return new $type($this->backingData);
|
||||
} else {
|
||||
throw new FacebookSDKException(
|
||||
'Cannot cast to an object that is not a GraphObject subclass', 620
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* asArray - Return a key-value associative array for the given graph object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function asArray()
|
||||
{
|
||||
return $this->backingData;
|
||||
}
|
||||
|
||||
/**
|
||||
* getProperty - Gets the value of the named property for this graph object,
|
||||
* cast to the appropriate subclass type if provided.
|
||||
*
|
||||
* @param string $name The property to retrieve
|
||||
* @param string $type The subclass of GraphObject, optionally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProperty($name, $type = 'Facebook\GraphObject')
|
||||
{
|
||||
if (isset($this->backingData[$name])) {
|
||||
$value = $this->backingData[$name];
|
||||
if (is_scalar($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return (new GraphObject($value))->cast($type);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getPropertyAsArray - Get the list value of a named property for this graph
|
||||
* object, where each item has been cast to the appropriate subclass type
|
||||
* if provided.
|
||||
*
|
||||
* Calling this for a property that is not an array, the behavior
|
||||
* is undefined, so don’t do this.
|
||||
*
|
||||
* @param string $name The property to retrieve
|
||||
* @param string $type The subclass of GraphObject, optionally
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyAsArray($name, $type = 'Facebook\GraphObject')
|
||||
{
|
||||
$target = array();
|
||||
if (isset($this->backingData[$name]['data'])) {
|
||||
$target = $this->backingData[$name]['data'];
|
||||
} else if (isset($this->backingData[$name])
|
||||
&& !is_scalar($this->backingData[$name])) {
|
||||
$target = $this->backingData[$name];
|
||||
}
|
||||
$out = array();
|
||||
foreach ($target as $key => $value) {
|
||||
if (is_scalar($value)) {
|
||||
$out[$key] = $value;
|
||||
} else {
|
||||
$out[$key] = (new GraphObject($value))->cast($type);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPropertyNames - Returns a list of all properties set on the object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyNames()
|
||||
{
|
||||
return array_keys($this->backingData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string class name of the GraphObject or subclass.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function className()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
}
|
64
external/facebook-sdk/src/Facebook/GraphPage.php
vendored
64
external/facebook-sdk/src/Facebook/GraphPage.php
vendored
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphPage
|
||||
* @package Facebook
|
||||
* @author Artur Luiz <artur@arturluiz.com.br>
|
||||
*/
|
||||
class GraphPage extends GraphObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the ID for the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getProperty('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Category for the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->getProperty('category');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Name of the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getProperty('name');
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphSessionInfo
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class GraphSessionInfo extends GraphObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the application id the token was issued for.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAppId()
|
||||
{
|
||||
return $this->getProperty('app_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the application name the token was issued for.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApplication()
|
||||
{
|
||||
return $this->getProperty('application');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date & time that the token expires.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getExpiresAt()
|
||||
{
|
||||
$stamp = $this->getProperty('expires_at');
|
||||
if ($stamp) {
|
||||
return (new \DateTime())->setTimestamp($stamp);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the token is valid.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
return $this->getProperty('is_valid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date & time the token was issued at.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getIssuedAt()
|
||||
{
|
||||
$stamp = $this->getProperty('issued_at');
|
||||
if ($stamp) {
|
||||
return (new \DateTime())->setTimestamp($stamp);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scope permissions associated with the token.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getScopes()
|
||||
{
|
||||
return $this->getPropertyAsArray('scopes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the login id of the user associated with the token.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getProperty('user_id');
|
||||
}
|
||||
|
||||
}
|
125
external/facebook-sdk/src/Facebook/GraphUser.php
vendored
125
external/facebook-sdk/src/Facebook/GraphUser.php
vendored
@ -1,125 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphUser
|
||||
* @package Facebook
|
||||
* @author Fosco Marotto <fjm@fb.com>
|
||||
* @author David Poll <depoll@fb.com>
|
||||
*/
|
||||
class GraphUser extends GraphObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the ID for the user as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getProperty('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name for the user as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getProperty('name');
|
||||
}
|
||||
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->getProperty('email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first name for the user as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->getProperty('first_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the middle name for the user as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMiddleName()
|
||||
{
|
||||
return $this->getProperty('middle_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last name for the user as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->getProperty('last_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Facebook URL for the user as a string if available.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLink()
|
||||
{
|
||||
return $this->getProperty('link');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the users birthday, if available.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getBirthday()
|
||||
{
|
||||
$value = $this->getProperty('birthday');
|
||||
if ($value) {
|
||||
return new \DateTime($value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current location of the user as a FacebookGraphLocation
|
||||
* if available.
|
||||
*
|
||||
* @return GraphLocation|null
|
||||
*/
|
||||
public function getLocation()
|
||||
{
|
||||
return $this->getProperty('location', GraphLocation::className());
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook;
|
||||
|
||||
/**
|
||||
* Class GraphUserPage
|
||||
* @package Facebook
|
||||
* @author Artur Luiz <artur@arturluiz.com.br>
|
||||
*/
|
||||
class GraphUserPage extends GraphObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the ID for the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getProperty('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Category for the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->getProperty('category');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Name of the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getProperty('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Access Token used to access the user's page as a string if present.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
return $this->getProperty('access_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Permissions for the user's page as an array if present.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getPermissions()
|
||||
{
|
||||
return $this->getProperty('perms');
|
||||
}
|
||||
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\HttpClients;
|
||||
|
||||
/**
|
||||
* Class FacebookCurl
|
||||
* Abstraction for the procedural curl elements so that curl can be mocked
|
||||
* and the implementation can be tested.
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookCurl
|
||||
{
|
||||
|
||||
/**
|
||||
* @var resource Curl resource instance
|
||||
*/
|
||||
protected $curl;
|
||||
|
||||
/**
|
||||
* Make a new curl reference instance
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->curl = curl_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a curl option
|
||||
*
|
||||
* @param $key
|
||||
* @param $value
|
||||
*/
|
||||
public function setopt($key, $value)
|
||||
{
|
||||
curl_setopt($this->curl, $key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an array of options to a curl resource
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function setopt_array(array $options)
|
||||
{
|
||||
curl_setopt_array($this->curl, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a curl request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function exec()
|
||||
{
|
||||
return curl_exec($this->curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the curl error number
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function errno()
|
||||
{
|
||||
return curl_errno($this->curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the curl error message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return curl_error($this->curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info from a curl reference
|
||||
*
|
||||
* @param $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getinfo($type)
|
||||
{
|
||||
return curl_getinfo($this->curl, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently installed curl version
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
return curl_version();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the resource connection to curl
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
curl_close($this->curl);
|
||||
}
|
||||
|
||||
}
|
@ -1,341 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\HttpClients;
|
||||
|
||||
use Facebook\FacebookSDKException;
|
||||
|
||||
/**
|
||||
* Class FacebookCurlHttpClient
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookCurlHttpClient implements FacebookHttpable
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array The headers to be sent with the request
|
||||
*/
|
||||
protected $requestHeaders = array();
|
||||
|
||||
/**
|
||||
* @var array The headers received from the response
|
||||
*/
|
||||
protected $responseHeaders = array();
|
||||
|
||||
/**
|
||||
* @var int The HTTP status code returned from the server
|
||||
*/
|
||||
protected $responseHttpStatusCode = 0;
|
||||
|
||||
/**
|
||||
* @var string The client error message
|
||||
*/
|
||||
protected $curlErrorMessage = '';
|
||||
|
||||
/**
|
||||
* @var int The curl client error code
|
||||
*/
|
||||
protected $curlErrorCode = 0;
|
||||
|
||||
/**
|
||||
* @var string|boolean The raw response from the server
|
||||
*/
|
||||
protected $rawResponse;
|
||||
|
||||
/**
|
||||
* @var FacebookCurl Procedural curl as object
|
||||
*/
|
||||
protected static $facebookCurl;
|
||||
|
||||
/**
|
||||
* @var boolean If IPv6 should be disabled
|
||||
*/
|
||||
protected static $disableIPv6;
|
||||
|
||||
/**
|
||||
* @const Curl Version which is unaffected by the proxy header length error.
|
||||
*/
|
||||
const CURL_PROXY_QUIRK_VER = 0x071E00;
|
||||
|
||||
/**
|
||||
* @const "Connection Established" header text
|
||||
*/
|
||||
const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n";
|
||||
|
||||
/**
|
||||
* @param FacebookCurl|null Procedural curl as object
|
||||
*/
|
||||
public function __construct(FacebookCurl $facebookCurl = null)
|
||||
{
|
||||
self::$facebookCurl = $facebookCurl ?: new FacebookCurl();
|
||||
self::$disableIPv6 = self::$disableIPv6 ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable IPv6 resolution
|
||||
*/
|
||||
public function disableIPv6()
|
||||
{
|
||||
self::$disableIPv6 = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers we want to send with the request
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function addRequestHeader($key, $value)
|
||||
{
|
||||
$this->requestHeaders[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers returned in the response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* The HTTP status response code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getResponseHttpStatusCode()
|
||||
{
|
||||
return $this->responseHttpStatusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the server
|
||||
*
|
||||
* @param string $url The endpoint to send the request to
|
||||
* @param string $method The request method
|
||||
* @param array $parameters The key value pairs to be sent in the body
|
||||
*
|
||||
* @return string Raw response from the server
|
||||
*
|
||||
* @throws \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function send($url, $method = 'GET', $parameters = array())
|
||||
{
|
||||
$this->openConnection($url, $method, $parameters);
|
||||
$this->tryToSendRequest();
|
||||
|
||||
// Need to verify the peer
|
||||
if ($this->curlErrorCode == 60 || $this->curlErrorCode == 77) {
|
||||
$this->addBundledCert();
|
||||
$this->tryToSendRequest();
|
||||
}
|
||||
|
||||
if ($this->curlErrorCode) {
|
||||
throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode);
|
||||
}
|
||||
|
||||
// Separate the raw headers from the raw body
|
||||
list($rawHeaders, $rawBody) = $this->extractResponseHeadersAndBody();
|
||||
|
||||
$this->responseHeaders = self::headersToArray($rawHeaders);
|
||||
|
||||
$this->closeConnection();
|
||||
|
||||
return $rawBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new curl connection
|
||||
*
|
||||
* @param string $url The endpoint to send the request to
|
||||
* @param string $method The request method
|
||||
* @param array $parameters The key value pairs to be sent in the body
|
||||
*/
|
||||
public function openConnection($url, $method = 'GET', $parameters = array())
|
||||
{
|
||||
$options = array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects
|
||||
CURLOPT_HEADER => true, // Enable header processing
|
||||
);
|
||||
|
||||
if ($method !== "GET") {
|
||||
$options[CURLOPT_POSTFIELDS] = $parameters;
|
||||
}
|
||||
if ($method === 'DELETE' || $method === 'PUT') {
|
||||
$options[CURLOPT_CUSTOMREQUEST] = $method;
|
||||
}
|
||||
|
||||
if (!empty($this->requestHeaders)) {
|
||||
$options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders();
|
||||
}
|
||||
|
||||
if (self::$disableIPv6) {
|
||||
$options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
|
||||
}
|
||||
|
||||
self::$facebookCurl->init();
|
||||
self::$facebookCurl->setopt_array($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bundled cert to the connection
|
||||
*/
|
||||
public function addBundledCert()
|
||||
{
|
||||
self::$facebookCurl->setopt(CURLOPT_CAINFO,
|
||||
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt');
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes an existing curl connection
|
||||
*/
|
||||
public function closeConnection()
|
||||
{
|
||||
self::$facebookCurl->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to send the request
|
||||
*/
|
||||
public function tryToSendRequest()
|
||||
{
|
||||
$this->sendRequest();
|
||||
$this->curlErrorMessage = self::$facebookCurl->error();
|
||||
$this->curlErrorCode = self::$facebookCurl->errno();
|
||||
$this->responseHttpStatusCode = self::$facebookCurl->getinfo(CURLINFO_HTTP_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the request and get the raw response from curl
|
||||
*/
|
||||
public function sendRequest()
|
||||
{
|
||||
$this->rawResponse = self::$facebookCurl->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the request headers into a curl-friendly format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function compileRequestHeaders()
|
||||
{
|
||||
$return = array();
|
||||
|
||||
foreach ($this->requestHeaders as $key => $value) {
|
||||
$return[] = $key . ': ' . $value;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the headers and the body into a two-part array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function extractResponseHeadersAndBody()
|
||||
{
|
||||
$headerSize = self::getHeaderSize();
|
||||
|
||||
$rawHeaders = mb_substr($this->rawResponse, 0, $headerSize);
|
||||
$rawBody = mb_substr($this->rawResponse, $headerSize);
|
||||
|
||||
return array(trim($rawHeaders), trim($rawBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts raw header responses into an array
|
||||
*
|
||||
* @param string $rawHeaders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function headersToArray($rawHeaders)
|
||||
{
|
||||
$headers = array();
|
||||
|
||||
// Normalize line breaks
|
||||
$rawHeaders = str_replace("\r\n", "\n", $rawHeaders);
|
||||
|
||||
// There will be multiple headers if a 301 was followed
|
||||
// or a proxy was followed, etc
|
||||
$headerCollection = explode("\n\n", trim($rawHeaders));
|
||||
// We just want the last response (at the end)
|
||||
$rawHeader = array_pop($headerCollection);
|
||||
|
||||
$headerComponents = explode("\n", $rawHeader);
|
||||
foreach ($headerComponents as $line) {
|
||||
if (strpos($line, ': ') === false) {
|
||||
$headers['http_code'] = $line;
|
||||
} else {
|
||||
list ($key, $value) = explode(': ', $line);
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return proper header size
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function getHeaderSize()
|
||||
{
|
||||
$headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE);
|
||||
// This corrects a Curl bug where header size does not account
|
||||
// for additional Proxy headers.
|
||||
if ( self::needsCurlProxyFix() ) {
|
||||
// Additional way to calculate the request body size.
|
||||
if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) {
|
||||
$headerSize = mb_strlen($this->rawResponse) - $m[1];
|
||||
} elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) {
|
||||
$headerSize += mb_strlen(self::CONNECTION_ESTABLISHED);
|
||||
}
|
||||
}
|
||||
|
||||
return $headerSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect versions of Curl which report incorrect header lengths when
|
||||
* using Proxies.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function needsCurlProxyFix()
|
||||
{
|
||||
$ver = self::$facebookCurl->version();
|
||||
$version = $ver['version_number'];
|
||||
|
||||
return $version < self::CURL_PROXY_QUIRK_VER;
|
||||
}
|
||||
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\HttpClients;
|
||||
|
||||
use Facebook\FacebookSDKException;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\AdapterException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
class FacebookGuzzleHttpClient implements FacebookHttpable {
|
||||
|
||||
/**
|
||||
* @var array The headers to be sent with the request
|
||||
*/
|
||||
protected $requestHeaders = array();
|
||||
|
||||
/**
|
||||
* @var array The headers received from the response
|
||||
*/
|
||||
protected $responseHeaders = array();
|
||||
|
||||
/**
|
||||
* @var int The HTTP status code returned from the server
|
||||
*/
|
||||
protected $responseHttpStatusCode = 0;
|
||||
|
||||
/**
|
||||
* @var \GuzzleHttp\Client The Guzzle client
|
||||
*/
|
||||
protected static $guzzleClient;
|
||||
|
||||
/**
|
||||
* @param \GuzzleHttp\Client|null The Guzzle client
|
||||
*/
|
||||
public function __construct(Client $guzzleClient = null)
|
||||
{
|
||||
self::$guzzleClient = $guzzleClient ?: new Client();
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers we want to send with the request
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function addRequestHeader($key, $value)
|
||||
{
|
||||
$this->requestHeaders[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers returned in the response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* The HTTP status response code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getResponseHttpStatusCode()
|
||||
{
|
||||
return $this->responseHttpStatusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the server
|
||||
*
|
||||
* @param string $url The endpoint to send the request to
|
||||
* @param string $method The request method
|
||||
* @param array $parameters The key value pairs to be sent in the body
|
||||
*
|
||||
* @return string Raw response from the server
|
||||
*
|
||||
* @throws \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function send($url, $method = 'GET', $parameters = array())
|
||||
{
|
||||
$options = array();
|
||||
if ($parameters) {
|
||||
$options = array('body' => $parameters);
|
||||
}
|
||||
|
||||
$request = self::$guzzleClient->createRequest($method, $url, $options);
|
||||
|
||||
foreach($this->requestHeaders as $k => $v) {
|
||||
$request->setHeader($k, $v);
|
||||
}
|
||||
|
||||
try {
|
||||
$rawResponse = self::$guzzleClient->send($request);
|
||||
} catch (RequestException $e) {
|
||||
if ($e->getPrevious() instanceof AdapterException) {
|
||||
throw new FacebookSDKException($e->getMessage(), $e->getCode());
|
||||
}
|
||||
$rawResponse = $e->getResponse();
|
||||
}
|
||||
|
||||
$this->responseHttpStatusCode = $rawResponse->getStatusCode();
|
||||
$this->responseHeaders = $rawResponse->getHeaders();
|
||||
|
||||
return $rawResponse->getBody();
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\HttpClients;
|
||||
|
||||
/**
|
||||
* Interface FacebookHttpable
|
||||
* @package Facebook
|
||||
*/
|
||||
interface FacebookHttpable
|
||||
{
|
||||
|
||||
/**
|
||||
* The headers we want to send with the request
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function addRequestHeader($key, $value);
|
||||
|
||||
/**
|
||||
* The headers returned in the response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseHeaders();
|
||||
|
||||
/**
|
||||
* The HTTP status response code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getResponseHttpStatusCode();
|
||||
|
||||
/**
|
||||
* Sends a request to the server
|
||||
*
|
||||
* @param string $url The endpoint to send the request to
|
||||
* @param string $method The request method
|
||||
* @param array $parameters The key value pairs to be sent in the body
|
||||
*
|
||||
* @return string Raw response from the server
|
||||
*
|
||||
* @throws \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function send($url, $method = 'GET', $parameters = array());
|
||||
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\HttpClients;
|
||||
|
||||
/**
|
||||
* Class FacebookStream
|
||||
* Abstraction for the procedural stream elements so that the functions can be
|
||||
* mocked and the implementation can be tested.
|
||||
* @package Facebook
|
||||
*/
|
||||
class FacebookStream
|
||||
{
|
||||
|
||||
/**
|
||||
* @var resource Context stream resource instance
|
||||
*/
|
||||
protected $stream;
|
||||
|
||||
/**
|
||||
* @var array Response headers from the stream wrapper
|
||||
*/
|
||||
protected $responseHeaders;
|
||||
|
||||
/**
|
||||
* Make a new context stream reference instance
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function streamContextCreate(array $options)
|
||||
{
|
||||
$this->stream = stream_context_create($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* The response headers from the stream wrapper
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a stream wrapped request
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function fileGetContents($url)
|
||||
{
|
||||
$rawResponse = file_get_contents($url, false, $this->stream);
|
||||
$this->responseHeaders = $http_response_header;
|
||||
return $rawResponse;
|
||||
}
|
||||
|
||||
}
|
@ -1,188 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2014 Facebook, Inc.
|
||||
*
|
||||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
||||
* use, copy, modify, and distribute this software in source code or binary
|
||||
* form for use in connection with the web services and APIs provided by
|
||||
* Facebook.
|
||||
*
|
||||
* As with any software that integrates with the Facebook platform, your use
|
||||
* of this software is subject to the Facebook Developer Principles and
|
||||
* Policies [http://developers.facebook.com/policy/]. This copyright notice
|
||||
* shall be included in all copies or substantial portions of the software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
namespace Facebook\HttpClients;
|
||||
|
||||
use Facebook\FacebookSDKException;
|
||||
|
||||
class FacebookStreamHttpClient implements FacebookHttpable {
|
||||
|
||||
/**
|
||||
* @var array The headers to be sent with the request
|
||||
*/
|
||||
protected $requestHeaders = array();
|
||||
|
||||
/**
|
||||
* @var array The headers received from the response
|
||||
*/
|
||||
protected $responseHeaders = array();
|
||||
|
||||
/**
|
||||
* @var int The HTTP status code returned from the server
|
||||
*/
|
||||
protected $responseHttpStatusCode = 0;
|
||||
|
||||
/**
|
||||
* @var FacebookStream Procedural stream wrapper as object
|
||||
*/
|
||||
protected static $facebookStream;
|
||||
|
||||
/**
|
||||
* @param FacebookStream|null Procedural stream wrapper as object
|
||||
*/
|
||||
public function __construct(FacebookStream $facebookStream = null)
|
||||
{
|
||||
self::$facebookStream = $facebookStream ?: new FacebookStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers we want to send with the request
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function addRequestHeader($key, $value)
|
||||
{
|
||||
$this->requestHeaders[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The headers returned in the response
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* The HTTP status response code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getResponseHttpStatusCode()
|
||||
{
|
||||
return $this->responseHttpStatusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the server
|
||||
*
|
||||
* @param string $url The endpoint to send the request to
|
||||
* @param string $method The request method
|
||||
* @param array $parameters The key value pairs to be sent in the body
|
||||
*
|
||||
* @return string Raw response from the server
|
||||
*
|
||||
* @throws \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function send($url, $method = 'GET', $parameters = array())
|
||||
{
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'method' => $method,
|
||||
'timeout' => 60,
|
||||
'ignore_errors' => true
|
||||
),
|
||||
'ssl' => array(
|
||||
'verify_peer' => true,
|
||||
'cafile' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt',
|
||||
),
|
||||
);
|
||||
|
||||
if ($parameters) {
|
||||
$options['http']['content'] = http_build_query($parameters, null, '&');
|
||||
|
||||
$this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
$options['http']['header'] = $this->compileHeader();
|
||||
|
||||
self::$facebookStream->streamContextCreate($options);
|
||||
$rawResponse = self::$facebookStream->fileGetContents($url);
|
||||
$rawHeaders = self::$facebookStream->getResponseHeaders();
|
||||
|
||||
if ($rawResponse === false || !$rawHeaders) {
|
||||
throw new FacebookSDKException('Stream returned an empty response', 660);
|
||||
}
|
||||
|
||||
$this->responseHeaders = self::formatHeadersToArray($rawHeaders);
|
||||
$this->responseHttpStatusCode = self::getStatusCodeFromHeader($this->responseHeaders['http_code']);
|
||||
|
||||
return $rawResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the headers for use in the stream wrapper
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileHeader()
|
||||
{
|
||||
$header = [];
|
||||
foreach($this->requestHeaders as $k => $v) {
|
||||
$header[] = $k . ': ' . $v;
|
||||
}
|
||||
|
||||
return implode("\r\n", $header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts array of headers returned from the wrapper into
|
||||
* something standard
|
||||
*
|
||||
* @param array $rawHeaders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formatHeadersToArray(array $rawHeaders)
|
||||
{
|
||||
$headers = array();
|
||||
|
||||
foreach ($rawHeaders as $line) {
|
||||
if (strpos($line, ':') === false) {
|
||||
$headers['http_code'] = $line;
|
||||
} else {
|
||||
list ($key, $value) = explode(': ', $line);
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls out the HTTP status code from a response header
|
||||
*
|
||||
* @param string $header
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getStatusCodeFromHeader($header)
|
||||
{
|
||||
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $header, $match);
|
||||
return (int) $match[1];
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,247 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
use Facebook\Entities\AccessToken;
|
||||
|
||||
class AccessTokenTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testAnAccessTokenCanBeReturnedAsAString()
|
||||
{
|
||||
$accessToken = new AccessToken('foo_token');
|
||||
|
||||
$this->assertEquals('foo_token', (string) $accessToken);
|
||||
}
|
||||
|
||||
public function testShortLivedAccessTokensCanBeDetected()
|
||||
{
|
||||
$anHourAndAHalf = time() + (1.5 * 60);
|
||||
$accessToken = new AccessToken('foo_token', $anHourAndAHalf);
|
||||
|
||||
$isLongLived = $accessToken->isLongLived();
|
||||
|
||||
$this->assertFalse($isLongLived, 'Expected access token to be short lived.');
|
||||
}
|
||||
|
||||
public function testLongLivedAccessTokensCanBeDetected()
|
||||
{
|
||||
$aWeek = time() + (60 * 60 * 24 * 7);
|
||||
$accessToken = new AccessToken('foo_token', $aWeek);
|
||||
|
||||
$isLongLived = $accessToken->isLongLived();
|
||||
|
||||
$this->assertTrue($isLongLived, 'Expected access token to be long lived.');
|
||||
}
|
||||
|
||||
public function testATokenIsValidatedOnTheAppIdAndMachineIdAndTokenValidityAndTokenExpiration()
|
||||
{
|
||||
$aWeek = time() + (60 * 60 * 24 * 7);
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($aWeek);
|
||||
|
||||
$graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getAppId')
|
||||
->once()
|
||||
->andReturn('123');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getProperty')
|
||||
->with('machine_id')
|
||||
->once()
|
||||
->andReturn('foo_machine');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('isValid')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getExpiresAt')
|
||||
->twice()
|
||||
->andReturn($dt);
|
||||
|
||||
$isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'foo_machine');
|
||||
|
||||
$this->assertTrue($isValid, 'Expected access token to be valid.');
|
||||
}
|
||||
|
||||
public function testATokenWillNotBeValidIfTheAppIdDoesNotMatch()
|
||||
{
|
||||
$aWeek = time() + (60 * 60 * 24 * 7);
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($aWeek);
|
||||
|
||||
$graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getAppId')
|
||||
->once()
|
||||
->andReturn('123');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getProperty')
|
||||
->with('machine_id')
|
||||
->once()
|
||||
->andReturn('foo_machine');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('isValid')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getExpiresAt')
|
||||
->twice()
|
||||
->andReturn($dt);
|
||||
|
||||
$isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '42', 'foo_machine');
|
||||
|
||||
$this->assertFalse($isValid, 'Expected access token to be invalid because the app ID does not match.');
|
||||
}
|
||||
|
||||
public function testATokenWillNotBeValidIfTheMachineIdDoesNotMatch()
|
||||
{
|
||||
$aWeek = time() + (60 * 60 * 24 * 7);
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($aWeek);
|
||||
|
||||
$graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getAppId')
|
||||
->once()
|
||||
->andReturn('123');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getProperty')
|
||||
->with('machine_id')
|
||||
->once()
|
||||
->andReturn('foo_machine');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('isValid')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getExpiresAt')
|
||||
->twice()
|
||||
->andReturn($dt);
|
||||
|
||||
$isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'bar_machine');
|
||||
|
||||
$this->assertFalse($isValid, 'Expected access token to be invalid because the machine ID does not match.');
|
||||
}
|
||||
|
||||
public function testATokenWillNotBeValidIfTheCollectionTellsUsItsNotValid()
|
||||
{
|
||||
$aWeek = time() + (60 * 60 * 24 * 7);
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($aWeek);
|
||||
|
||||
$graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getAppId')
|
||||
->once()
|
||||
->andReturn('123');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getProperty')
|
||||
->with('machine_id')
|
||||
->once()
|
||||
->andReturn('foo_machine');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('isValid')
|
||||
->once()
|
||||
->andReturn(false);
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getExpiresAt')
|
||||
->twice()
|
||||
->andReturn($dt);
|
||||
|
||||
$isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'foo_machine');
|
||||
|
||||
$this->assertFalse($isValid, 'Expected access token to be invalid because the collection says it is not valid.');
|
||||
}
|
||||
|
||||
public function testATokenWillNotBeValidIfTheTokenHasExpired()
|
||||
{
|
||||
$lastWeek = time() - (60 * 60 * 24 * 7);
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($lastWeek);
|
||||
|
||||
$graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getAppId')
|
||||
->once()
|
||||
->andReturn('123');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getProperty')
|
||||
->with('machine_id')
|
||||
->once()
|
||||
->andReturn('foo_machine');
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('isValid')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
$graphSessionInfoMock
|
||||
->shouldReceive('getExpiresAt')
|
||||
->twice()
|
||||
->andReturn($dt);
|
||||
|
||||
$isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'foo_machine');
|
||||
|
||||
$this->assertFalse($isValid, 'Expected access token to be invalid because it has expired.');
|
||||
}
|
||||
|
||||
public function testInfoAboutAnAccessTokenCanBeObtainedFromGraph()
|
||||
{
|
||||
$testUserAccessToken = FacebookTestHelper::$testUserAccessToken;
|
||||
|
||||
$accessToken = new AccessToken($testUserAccessToken);
|
||||
$accessTokenInfo = $accessToken->getInfo();
|
||||
|
||||
$testAppId = FacebookTestCredentials::$appId;
|
||||
$this->assertEquals($testAppId, $accessTokenInfo->getAppId());
|
||||
|
||||
$testUserId = FacebookTestHelper::$testUserId;
|
||||
$this->assertEquals($testUserId, $accessTokenInfo->getId());
|
||||
|
||||
$expectedScopes = FacebookTestHelper::$testUserPermissions;
|
||||
$actualScopes = $accessTokenInfo->getPropertyAsArray('scopes');
|
||||
foreach ($expectedScopes as $scope) {
|
||||
$this->assertTrue(in_array($scope, $actualScopes),
|
||||
'Expected the following permission to be present: '.$scope);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAShortLivedAccessTokenCabBeExtended()
|
||||
{
|
||||
$testUserAccessToken = FacebookTestHelper::$testUserAccessToken;
|
||||
|
||||
$accessToken = new AccessToken($testUserAccessToken);
|
||||
$longLivedAccessToken = $accessToken->extend();
|
||||
|
||||
$this->assertInstanceOf('Facebook\Entities\AccessToken', $longLivedAccessToken);
|
||||
}
|
||||
|
||||
public function testALongLivedAccessTokenCanBeUsedToObtainACode()
|
||||
{
|
||||
$testUserAccessToken = FacebookTestHelper::$testUserAccessToken;
|
||||
|
||||
$accessToken = new AccessToken($testUserAccessToken);
|
||||
$longLivedAccessToken = $accessToken->extend();
|
||||
|
||||
$code = AccessToken::getCodeFromAccessToken((string) $longLivedAccessToken);
|
||||
|
||||
$this->assertTrue(is_string($code));
|
||||
}
|
||||
|
||||
public function testACodeCanBeUsedToObtainAnAccessToken()
|
||||
{
|
||||
$testUserAccessToken = FacebookTestHelper::$testUserAccessToken;
|
||||
|
||||
$accessToken = new AccessToken($testUserAccessToken);
|
||||
$longLivedAccessToken = $accessToken->extend();
|
||||
|
||||
$code = AccessToken::getCodeFromAccessToken($longLivedAccessToken);
|
||||
$accessTokenFromCode = AccessToken::getAccessTokenFromCode($code);
|
||||
|
||||
$this->assertInstanceOf('Facebook\Entities\AccessToken', $accessTokenFromCode);
|
||||
}
|
||||
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\Entities\SignedRequest;
|
||||
|
||||
class SignedRequestTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public $appSecret = 'foo_app_secret';
|
||||
|
||||
public $rawSignedRequest = 'U0_O1MqqNKUt32633zAkdd2Ce-jGVgRgJeRauyx_zC8=.eyJvYXV0aF90b2tlbiI6ImZvb190b2tlbiIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjozMjEsImNvZGUiOiJmb29fY29kZSIsInN0YXRlIjoiZm9vX3N0YXRlIiwidXNlcl9pZCI6MTIzLCJmb28iOiJiYXIifQ==';
|
||||
|
||||
public $payloadData = array(
|
||||
'oauth_token' => 'foo_token',
|
||||
'algorithm' => 'HMAC-SHA256',
|
||||
'issued_at' => 321,
|
||||
'code' => 'foo_code',
|
||||
'state' => 'foo_state',
|
||||
'user_id' => 123,
|
||||
'foo' => 'bar',
|
||||
);
|
||||
|
||||
public function testValidSignedRequestsWillPassFormattingValidation()
|
||||
{
|
||||
$sr = SignedRequest::make($this->payloadData, $this->appSecret);
|
||||
SignedRequest::validateFormat($sr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testInvalidSignedRequestsWillFailFormattingValidation()
|
||||
{
|
||||
SignedRequest::validateFormat('invalid_signed_request');
|
||||
}
|
||||
|
||||
public function testSignatureAndPayloadCanBeSeparatedInSignedRequests()
|
||||
{
|
||||
list($sig, $payload) = SignedRequest::split('sig.payload');
|
||||
|
||||
$this->assertEquals('sig', $sig);
|
||||
$this->assertEquals('payload', $payload);
|
||||
}
|
||||
|
||||
public function testBase64EncodingIsUrlSafe()
|
||||
{
|
||||
$encodedData = SignedRequest::base64UrlEncode('aijkoprstADIJKLOPQTUVX1256!)]-:;"<>?.|~');
|
||||
|
||||
$this->assertEquals('YWlqa29wcnN0QURJSktMT1BRVFVWWDEyNTYhKV0tOjsiPD4_Lnx-', $encodedData);
|
||||
}
|
||||
|
||||
public function testAUrlSafeBase64EncodedStringCanBeDecoded()
|
||||
{
|
||||
$decodedData = SignedRequest::base64UrlDecode('YWlqa29wcnN0QURJSktMT1BRVFVWWDEyNTYhKV0tOjsiPD4/Lnx+');
|
||||
|
||||
$this->assertEquals('aijkoprstADIJKLOPQTUVX1256!)]-:;"<>?.|~', $decodedData);
|
||||
}
|
||||
|
||||
public function testAValidEncodedSignatureCanBeDecoded()
|
||||
{
|
||||
$decodedSig = SignedRequest::decodeSignature('c2ln');
|
||||
|
||||
$this->assertEquals('sig', $decodedSig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testAnImproperlyEncodedSignatureWillThrowAnException()
|
||||
{
|
||||
SignedRequest::decodeSignature('foo!');
|
||||
}
|
||||
|
||||
public function testAValidEncodedPayloadCanBeDecoded()
|
||||
{
|
||||
$decodedPayload = SignedRequest::decodePayload('WyJwYXlsb2FkIl0=');
|
||||
|
||||
$this->assertEquals(array('payload'), $decodedPayload);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testAnImproperlyEncodedPayloadWillThrowAnException()
|
||||
{
|
||||
SignedRequest::decodePayload('foo!');
|
||||
}
|
||||
|
||||
public function testSignedRequestDataMustContainTheHmacSha256Algorithm()
|
||||
{
|
||||
SignedRequest::validateAlgorithm($this->payloadData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testNonApprovedAlgorithmsWillThrowAnException()
|
||||
{
|
||||
$signedRequestData = $this->payloadData;
|
||||
$signedRequestData['algorithm'] = 'FOO-ALGORITHM';
|
||||
SignedRequest::validateAlgorithm($signedRequestData);
|
||||
}
|
||||
|
||||
public function testASignatureHashCanBeGeneratedFromBase64EncodedData()
|
||||
{
|
||||
$hashedSig = SignedRequest::hashSignature('WyJwYXlsb2FkIl0=', $this->appSecret);
|
||||
|
||||
$expectedSig = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s=');
|
||||
$this->assertEquals($expectedSig, $hashedSig);
|
||||
}
|
||||
|
||||
public function testTwoBinaryStringsCanBeComparedForSignatureValidation()
|
||||
{
|
||||
$hashedSig = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s=');
|
||||
SignedRequest::validateSignature($hashedSig, $hashedSig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testNonSameBinaryStringsWillThrowAnExceptionForSignatureValidation()
|
||||
{
|
||||
$hashedSig1 = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s=');
|
||||
$hashedSig2 = base64_decode('GJy4HzkRtCeZA0cJjdZJtGfovcdxgl/AERI20S4MY7c=');
|
||||
SignedRequest::validateSignature($hashedSig1, $hashedSig2);
|
||||
}
|
||||
|
||||
public function testASignedRequestWillPassCsrfValidation()
|
||||
{
|
||||
SignedRequest::validateCsrf($this->payloadData, 'foo_state');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testASignedRequestWithIncorrectCsrfDataWillThrowAnException()
|
||||
{
|
||||
SignedRequest::validateCsrf($this->payloadData, 'invalid_foo_state');
|
||||
}
|
||||
|
||||
public function testARawSignedRequestCanBeValidatedAndDecoded()
|
||||
{
|
||||
$payload = SignedRequest::parse($this->rawSignedRequest, 'foo_state', $this->appSecret);
|
||||
|
||||
$this->assertEquals($this->payloadData, $payload);
|
||||
}
|
||||
|
||||
public function testARawSignedRequestCanBeInjectedIntoTheConstructorToInstantiateANewEntity()
|
||||
{
|
||||
$signedRequest = new SignedRequest($this->rawSignedRequest, 'foo_state', $this->appSecret);
|
||||
|
||||
$rawSignedRequest = $signedRequest->getRawSignedRequest();
|
||||
$payloadData = $signedRequest->getPayload();
|
||||
$userId = $signedRequest->getUserId();
|
||||
$hasOAuthData = $signedRequest->hasOAuthData();
|
||||
|
||||
$this->assertInstanceOf('\Facebook\Entities\SignedRequest', $signedRequest);
|
||||
$this->assertEquals($this->rawSignedRequest, $rawSignedRequest);
|
||||
$this->assertEquals($this->payloadData, $payloadData);
|
||||
$this->assertEquals(123, $userId);
|
||||
$this->assertTrue($hasOAuthData);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookCanvasLoginHelper;
|
||||
|
||||
class FacebookCanvasLoginHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public $rawSignedRequestAuthorized = 'vdZXlVEQ5NTRRTFvJ7Jeo_kP4SKnBDvbNP0fEYKS0Sg=.eyJvYXV0aF90b2tlbiI6ImZvb190b2tlbiIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjoxNDAyNTUxMDMxLCJ1c2VyX2lkIjoiMTIzIn0=';
|
||||
protected $helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->helper = new FacebookCanvasLoginHelper('123', 'foo_app_secret');
|
||||
}
|
||||
|
||||
public function testSignedRequestDataCanBeRetrievedFromPostData()
|
||||
{
|
||||
$_POST['signed_request'] = $this->rawSignedRequestAuthorized;
|
||||
|
||||
$rawSignedRequest = $this->helper->getRawSignedRequest();
|
||||
|
||||
$this->assertEquals($this->rawSignedRequestAuthorized, $rawSignedRequest);
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookJavaScriptLoginHelper;
|
||||
|
||||
class FacebookJavaScriptLoginHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public $appId = '123';
|
||||
public $appSecret = 'foo_app_secret';
|
||||
public $rawSignedRequestAuthorized = 'vdZXlVEQ5NTRRTFvJ7Jeo_kP4SKnBDvbNP0fEYKS0Sg=.eyJvYXV0aF90b2tlbiI6ImZvb190b2tlbiIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjoxNDAyNTUxMDMxLCJ1c2VyX2lkIjoiMTIzIn0=';
|
||||
|
||||
public function testARawSignedRequestCanBeRetrievedFromCookieData()
|
||||
{
|
||||
$_COOKIE['fbsr_123'] = $this->rawSignedRequestAuthorized;
|
||||
|
||||
$helper = new FacebookJavaScriptLoginHelper($this->appId, $this->appSecret);
|
||||
|
||||
$rawSignedRequest = $helper->getRawSignedRequest();
|
||||
|
||||
$this->assertEquals($this->rawSignedRequestAuthorized, $rawSignedRequest);
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookPageTabHelper;
|
||||
|
||||
class FacebookPageTabHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $rawSignedRequestAuthorized = '6Hi26ECjkj347belC0O8b8H5lwiIz5eA6V9VVjTg-HU=.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MzIxLCJvYXV0aF90b2tlbiI6ImZvb190b2tlbiIsInVzZXJfaWQiOiIxMjMiLCJwYWdlIjp7ImlkIjoiNDIiLCJsaWtlZCI6dHJ1ZSwiYWRtaW4iOmZhbHNlfX0=';
|
||||
|
||||
public function testPageDataCanBeAccessed()
|
||||
{
|
||||
$_GET['signed_request'] = $this->rawSignedRequestAuthorized;
|
||||
$helper = new FacebookPageTabHelper('123', 'foo_app_secret');
|
||||
|
||||
$this->assertTrue($helper->isLiked());
|
||||
$this->assertFalse($helper->isAdmin());
|
||||
$this->assertEquals('42', $helper->getPageId());
|
||||
$this->assertEquals('42', $helper->getPageData('id'));
|
||||
$this->assertEquals('default', $helper->getPageData('foo', 'default'));
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRedirectLoginHelper;
|
||||
use Facebook\FacebookRequest;
|
||||
|
||||
class FacebookRedirectLoginHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
const REDIRECT_URL = 'http://invalid.zzz';
|
||||
|
||||
public function testLoginURL()
|
||||
{
|
||||
$helper = new FacebookRedirectLoginHelper(
|
||||
self::REDIRECT_URL,
|
||||
FacebookTestCredentials::$appId,
|
||||
FacebookTestCredentials::$appSecret
|
||||
);
|
||||
$helper->disableSessionStatusCheck();
|
||||
$loginUrl = $helper->getLoginUrl();
|
||||
$state = $_SESSION['FBRLH_state'];
|
||||
$params = array(
|
||||
'client_id' => FacebookTestCredentials::$appId,
|
||||
'redirect_uri' => self::REDIRECT_URL,
|
||||
'state' => $state,
|
||||
'sdk' => 'php-sdk-' . FacebookRequest::VERSION,
|
||||
'scope' => implode(',', array())
|
||||
);
|
||||
$expectedUrl = 'https://www.facebook.com/v2.0/dialog/oauth?';
|
||||
$this->assertTrue(strpos($loginUrl, $expectedUrl) !== false);
|
||||
foreach ($params as $key => $value) {
|
||||
$this->assertTrue(
|
||||
strpos($loginUrl, $key . '=' . urlencode($value)) !== false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testLogoutURL()
|
||||
{
|
||||
$helper = new FacebookRedirectLoginHelper(
|
||||
self::REDIRECT_URL,
|
||||
FacebookTestCredentials::$appId,
|
||||
FacebookTestCredentials::$appSecret
|
||||
);
|
||||
$helper->disableSessionStatusCheck();
|
||||
$logoutUrl = $helper->getLogoutUrl(
|
||||
FacebookTestHelper::$testSession, self::REDIRECT_URL
|
||||
);
|
||||
$params = array(
|
||||
'next' => self::REDIRECT_URL,
|
||||
'access_token' => FacebookTestHelper::$testSession->getToken()
|
||||
);
|
||||
$expectedUrl = 'https://www.facebook.com/logout.php?';
|
||||
$this->assertTrue(strpos($logoutUrl, $expectedUrl) !== false);
|
||||
foreach ($params as $key => $value) {
|
||||
$this->assertTrue(
|
||||
strpos($logoutUrl, $key . '=' . urlencode($value)) !== false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCSPRNG()
|
||||
{
|
||||
$helper = new FacebookRedirectLoginHelper(
|
||||
self::REDIRECT_URL,
|
||||
FacebookTestCredentials::$appId,
|
||||
FacebookTestCredentials::$appSecret
|
||||
);
|
||||
$this->assertEquals(1, preg_match('/^([0-9a-f]+)$/', $helper->random(32)));
|
||||
}
|
||||
|
||||
}
|
@ -1,266 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRequestException;
|
||||
use Facebook\FacebookAuthorizationException;
|
||||
use Facebook\FacebookOtherException;
|
||||
use Facebook\FacebookServerException;
|
||||
use Facebook\FacebookPermissionException;
|
||||
use Facebook\FacebookClientException;
|
||||
use Facebook\FacebookThrottleException;
|
||||
use Facebook\FacebookSession;
|
||||
|
||||
class FacebookRequestExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testAuthorizationExceptions()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 100,
|
||||
'message' => 'errmsg',
|
||||
'error_subcode' => 0,
|
||||
'type' => 'exception'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(100, $exception->getCode());
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
$this->assertEquals('exception', $exception->getErrorType());
|
||||
$this->assertEquals('errmsg', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(401, $exception->getHttpStatusCode());
|
||||
|
||||
$params['error']['code'] = 102;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(102, $exception->getCode());
|
||||
|
||||
$params['error']['code'] = 190;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(190, $exception->getCode());
|
||||
|
||||
$params['error']['type'] = 'OAuthException';
|
||||
$params['error']['code'] = 0;
|
||||
$params['error']['error_subcode'] = 458;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(458, $exception->getSubErrorCode());
|
||||
|
||||
$params['error']['error_subcode'] = 460;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(460, $exception->getSubErrorCode());
|
||||
|
||||
$params['error']['error_subcode'] = 463;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(463, $exception->getSubErrorCode());
|
||||
|
||||
$params['error']['error_subcode'] = 467;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(467, $exception->getSubErrorCode());
|
||||
|
||||
$params['error']['error_subcode'] = 0;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
}
|
||||
|
||||
public function testServerExceptions()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 1,
|
||||
'message' => 'errmsg',
|
||||
'error_subcode' => 0,
|
||||
'type' => 'exception'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 500);
|
||||
$this->assertTrue($exception instanceof FacebookServerException);
|
||||
$this->assertEquals(1, $exception->getCode());
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
$this->assertEquals('exception', $exception->getErrorType());
|
||||
$this->assertEquals('errmsg', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(500, $exception->getHttpStatusCode());
|
||||
|
||||
$params['error']['code'] = 2;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookServerException);
|
||||
$this->assertEquals(2, $exception->getCode());
|
||||
}
|
||||
|
||||
public function testThrottleExceptions()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 4,
|
||||
'message' => 'errmsg',
|
||||
'error_subcode' => 0,
|
||||
'type' => 'exception'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookThrottleException);
|
||||
$this->assertEquals(4, $exception->getCode());
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
$this->assertEquals('exception', $exception->getErrorType());
|
||||
$this->assertEquals('errmsg', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(401, $exception->getHttpStatusCode());
|
||||
|
||||
$params['error']['code'] = 17;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookThrottleException);
|
||||
$this->assertEquals(17, $exception->getCode());
|
||||
|
||||
$params['error']['code'] = 341;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookThrottleException);
|
||||
$this->assertEquals(341, $exception->getCode());
|
||||
}
|
||||
|
||||
public function testUserIssueExceptions()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 230,
|
||||
'message' => 'errmsg',
|
||||
'error_subcode' => 459,
|
||||
'type' => 'exception'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(230, $exception->getCode());
|
||||
$this->assertEquals(459, $exception->getSubErrorCode());
|
||||
$this->assertEquals('exception', $exception->getErrorType());
|
||||
$this->assertEquals('errmsg', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(401, $exception->getHttpStatusCode());
|
||||
|
||||
$params['error']['error_subcode'] = 464;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookAuthorizationException);
|
||||
$this->assertEquals(464, $exception->getSubErrorCode());
|
||||
}
|
||||
|
||||
public function testPermissionExceptions()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 10,
|
||||
'message' => 'errmsg',
|
||||
'error_subcode' => 0,
|
||||
'type' => 'exception'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookPermissionException);
|
||||
$this->assertEquals(10, $exception->getCode());
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
$this->assertEquals('exception', $exception->getErrorType());
|
||||
$this->assertEquals('errmsg', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(401, $exception->getHttpStatusCode());
|
||||
|
||||
$params['error']['code'] = 200;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookPermissionException);
|
||||
$this->assertEquals(200, $exception->getCode());
|
||||
|
||||
$params['error']['code'] = 250;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookPermissionException);
|
||||
$this->assertEquals(250, $exception->getCode());
|
||||
|
||||
$params['error']['code'] = 299;
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookPermissionException);
|
||||
$this->assertEquals(299, $exception->getCode());
|
||||
}
|
||||
|
||||
public function testClientExceptions()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 506,
|
||||
'message' => 'errmsg',
|
||||
'error_subcode' => 0,
|
||||
'type' => 'exception'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 401);
|
||||
$this->assertTrue($exception instanceof FacebookClientException);
|
||||
$this->assertEquals(506, $exception->getCode());
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
$this->assertEquals('exception', $exception->getErrorType());
|
||||
$this->assertEquals('errmsg', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(401, $exception->getHttpStatusCode());
|
||||
}
|
||||
|
||||
public function testOtherException()
|
||||
{
|
||||
$params = array(
|
||||
'error' => array(
|
||||
'code' => 42,
|
||||
'message' => 'ship love',
|
||||
'error_subcode' => 0,
|
||||
'type' => 'feature'
|
||||
)
|
||||
);
|
||||
$json = json_encode($params);
|
||||
$exception = FacebookRequestException::create($json, $params, 200);
|
||||
$this->assertTrue($exception instanceof FacebookOtherException);
|
||||
$this->assertEquals(42, $exception->getCode());
|
||||
$this->assertEquals(0, $exception->getSubErrorCode());
|
||||
$this->assertEquals('feature', $exception->getErrorType());
|
||||
$this->assertEquals('ship love', $exception->getMessage());
|
||||
$this->assertEquals($json, $exception->getRawResponse());
|
||||
$this->assertEquals(200, $exception->getHttpStatusCode());
|
||||
}
|
||||
|
||||
public function testValidateThrowsException()
|
||||
{
|
||||
$bogusSession = new FacebookSession('invalid-token');
|
||||
$this->setExpectedException(
|
||||
'Facebook\\FacebookSDKException', 'Session has expired'
|
||||
);
|
||||
$bogusSession->validate();
|
||||
}
|
||||
|
||||
public function testInvalidCredentialsException()
|
||||
{
|
||||
$bogusSession = new FacebookSession('invalid-token');
|
||||
$this->setExpectedException(
|
||||
'Facebook\\FacebookAuthorizationException', 'Invalid OAuth access token'
|
||||
);
|
||||
$bogusSession->validate('invalid-app-id', 'invalid-app-secret');
|
||||
}
|
||||
|
||||
}
|
140
external/facebook-sdk/tests/FacebookRequestTest.php
vendored
140
external/facebook-sdk/tests/FacebookRequestTest.php
vendored
@ -1,140 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\FacebookSession;
|
||||
|
||||
class FacebookRequestTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGetsTheLoggedInUsersProfile()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/me'
|
||||
))->execute()->getGraphObject();
|
||||
$this->assertNotNull($response->getProperty('id'));
|
||||
$this->assertNotNull($response->getProperty('name'));
|
||||
}
|
||||
|
||||
public function testCanPostAndDelete()
|
||||
{
|
||||
// Create a test user
|
||||
$params = array(
|
||||
'name' => 'Foo User',
|
||||
);
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
new FacebookSession(FacebookTestHelper::getAppToken()),
|
||||
'POST',
|
||||
'/' . FacebookTestCredentials::$appId . '/accounts/test-users',
|
||||
$params
|
||||
))->execute()->getGraphObject();
|
||||
$user_id = $response->getProperty('id');
|
||||
$this->assertNotNull($user_id);
|
||||
|
||||
// Delete test user
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
new FacebookSession(FacebookTestHelper::getAppToken()),
|
||||
'DELETE',
|
||||
'/' . $user_id
|
||||
))->execute()->getGraphObject()->asArray();
|
||||
$this->assertTrue($response);
|
||||
}
|
||||
|
||||
public function testETagHit()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/104048449631599'
|
||||
))->execute();
|
||||
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/104048449631599',
|
||||
null,
|
||||
null,
|
||||
$response->getETag()
|
||||
))->execute();
|
||||
|
||||
$this->assertTrue($response->isETagHit());
|
||||
$this->assertNull($response->getETag());
|
||||
}
|
||||
|
||||
public function testETagMiss()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/104048449631599',
|
||||
null,
|
||||
null,
|
||||
'someRandomValue'
|
||||
))->execute();
|
||||
|
||||
$this->assertFalse($response->isETagHit());
|
||||
$this->assertNotNull($response->getETag());
|
||||
}
|
||||
|
||||
public function testGracefullyHandlesUrlAppending()
|
||||
{
|
||||
$params = array();
|
||||
$url = 'https://www.foo.com/';
|
||||
$processed_url = FacebookRequest::appendParamsToUrl($url, $params);
|
||||
$this->assertEquals('https://www.foo.com/', $processed_url);
|
||||
|
||||
$params = array(
|
||||
'access_token' => 'foo',
|
||||
);
|
||||
$url = 'https://www.foo.com/';
|
||||
$processed_url = FacebookRequest::appendParamsToUrl($url, $params);
|
||||
$this->assertEquals('https://www.foo.com/?access_token=foo', $processed_url);
|
||||
|
||||
$params = array(
|
||||
'access_token' => 'foo',
|
||||
'bar' => 'baz',
|
||||
);
|
||||
$url = 'https://www.foo.com/?foo=bar';
|
||||
$processed_url = FacebookRequest::appendParamsToUrl($url, $params);
|
||||
$this->assertEquals('https://www.foo.com/?access_token=foo&bar=baz&foo=bar', $processed_url);
|
||||
|
||||
$params = array(
|
||||
'access_token' => 'foo',
|
||||
);
|
||||
$url = 'https://www.foo.com/?foo=bar&access_token=bar';
|
||||
$processed_url = FacebookRequest::appendParamsToUrl($url, $params);
|
||||
$this->assertEquals('https://www.foo.com/?access_token=bar&foo=bar', $processed_url);
|
||||
}
|
||||
|
||||
public function testAppSecretProof()
|
||||
{
|
||||
$enableAppSecretProof = FacebookSession::useAppSecretProof();
|
||||
|
||||
FacebookSession::enableAppSecretProof(true);
|
||||
$request = new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/me'
|
||||
);
|
||||
$this->assertTrue(isset($request->getParameters()['appsecret_proof']));
|
||||
|
||||
|
||||
FacebookSession::enableAppSecretProof(false);
|
||||
$request = new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/me'
|
||||
);
|
||||
$this->assertFalse(isset($request->getParameters()['appsecret_proof']));
|
||||
|
||||
FacebookSession::enableAppSecretProof($enableAppSecretProof);
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
use Facebook\FacebookSession;
|
||||
use Facebook\GraphSessionInfo;
|
||||
|
||||
class FacebookSessionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testSessionToken()
|
||||
{
|
||||
$session = new FacebookSession(FacebookTestHelper::getAppToken());
|
||||
$this->assertEquals(
|
||||
FacebookTestHelper::getAppToken(), $session->getToken()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetSessionInfo()
|
||||
{
|
||||
$response = FacebookTestHelper::$testSession->getSessionInfo();
|
||||
$this->assertTrue($response instanceof GraphSessionInfo);
|
||||
$this->assertNotNull($response->getAppId());
|
||||
$this->assertTrue($response->isValid());
|
||||
$scopes = $response->getPropertyAsArray('scopes');
|
||||
$this->assertTrue(is_array($scopes));
|
||||
$this->assertEquals(5, count($scopes));
|
||||
}
|
||||
|
||||
public function testExtendAccessToken()
|
||||
{
|
||||
$response = FacebookTestHelper::$testSession->getLongLivedSession();
|
||||
$this->assertTrue($response instanceof FacebookSession);
|
||||
$info = $response->getSessionInfo();
|
||||
$nextWeek = time() + (60 * 60 * 24 * 7);
|
||||
$this->assertTrue(
|
||||
$info->getProperty('expires_at') > $nextWeek
|
||||
);
|
||||
}
|
||||
|
||||
public function testSessionFromSignedRequest()
|
||||
{
|
||||
$signedRequest = m::mock('Facebook\Entities\SignedRequest');
|
||||
$signedRequest
|
||||
->shouldReceive('get')
|
||||
->with('code')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$signedRequest
|
||||
->shouldReceive('get')
|
||||
->with('oauth_token')
|
||||
->once()
|
||||
->andReturn('foo_token');
|
||||
$signedRequest
|
||||
->shouldReceive('get')
|
||||
->with('expires', 0)
|
||||
->once()
|
||||
->andReturn(time() + (60 * 60 * 24));
|
||||
$signedRequest
|
||||
->shouldReceive('getUserId')
|
||||
->once()
|
||||
->andReturn('123');
|
||||
|
||||
$session = FacebookSession::newSessionFromSignedRequest($signedRequest);
|
||||
$this->assertInstanceOf('Facebook\FacebookSession', $session);
|
||||
$this->assertEquals('foo_token', $session->getToken());
|
||||
$this->assertEquals('123', $session->getUserId());
|
||||
}
|
||||
|
||||
public function testAppSessionValidates()
|
||||
{
|
||||
$session = FacebookSession::newAppSession();
|
||||
try {
|
||||
$session->validate();
|
||||
} catch (\Facebook\FacebookSDKException $ex) {
|
||||
$this->fail('Exception thrown validating app session.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookSignedRequestFromInputHelper;
|
||||
|
||||
class FooSignedRequestHelper extends FacebookSignedRequestFromInputHelper {
|
||||
public function getRawSignedRequest() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class FacebookSignedRequestFromInputHelperTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $helper;
|
||||
public $rawSignedRequestAuthorized = 'vdZXlVEQ5NTRRTFvJ7Jeo_kP4SKnBDvbNP0fEYKS0Sg=.eyJvYXV0aF90b2tlbiI6ImZvb190b2tlbiIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjoxNDAyNTUxMDMxLCJ1c2VyX2lkIjoiMTIzIn0=';
|
||||
public $rawSignedRequestUnauthorized = 'KPlyhz-whtYAhHWr15N5TkbS_avz-2rUJFpFkfXKC88=.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTQwMjU1MTA4Nn0=';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->helper = new FooSignedRequestHelper('123', 'foo_app_secret');
|
||||
}
|
||||
|
||||
public function testSignedRequestDataCanBeRetrievedFromGetData()
|
||||
{
|
||||
$_GET['signed_request'] = 'foo_signed_request';
|
||||
|
||||
$rawSignedRequest = $this->helper->getRawSignedRequestFromGet();
|
||||
|
||||
$this->assertEquals('foo_signed_request', $rawSignedRequest);
|
||||
}
|
||||
|
||||
public function testSignedRequestDataCanBeRetrievedFromPostData()
|
||||
{
|
||||
$_POST['signed_request'] = 'foo_signed_request';
|
||||
|
||||
$rawSignedRequest = $this->helper->getRawSignedRequestFromPost();
|
||||
|
||||
$this->assertEquals('foo_signed_request', $rawSignedRequest);
|
||||
}
|
||||
|
||||
public function testSignedRequestDataCanBeRetrievedFromCookieData()
|
||||
{
|
||||
$_COOKIE['fbsr_123'] = 'foo_signed_request';
|
||||
|
||||
$rawSignedRequest = $this->helper->getRawSignedRequestFromCookie();
|
||||
|
||||
$this->assertEquals('foo_signed_request', $rawSignedRequest);
|
||||
}
|
||||
|
||||
public function testSessionWillBeNullWhenAUserHasNotYetAuthorizedTheApp()
|
||||
{
|
||||
$this->helper->instantiateSignedRequest($this->rawSignedRequestUnauthorized);
|
||||
$session = $this->helper->getSession();
|
||||
|
||||
$this->assertNull($session);
|
||||
}
|
||||
|
||||
public function testAFacebookSessionCanBeInstantiatedWhenAUserHasAuthorizedTheApp()
|
||||
{
|
||||
$this->helper->instantiateSignedRequest($this->rawSignedRequestAuthorized);
|
||||
$session = $this->helper->getSession();
|
||||
|
||||
$this->assertInstanceOf('Facebook\FacebookSession', $session);
|
||||
$this->assertEquals('foo_token', $session->getToken());
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
class FacebookTestCredentials {
|
||||
|
||||
/**
|
||||
* These must be filled out with valid Facebook app details for the tests to
|
||||
* run.
|
||||
*/
|
||||
public static $appId = '';
|
||||
public static $appSecret = '';
|
||||
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookSession;
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\FacebookSDKException;
|
||||
|
||||
class FacebookTestHelper
|
||||
{
|
||||
|
||||
public static $testSession;
|
||||
public static $testUserId;
|
||||
public static $testUserAccessToken;
|
||||
public static $testUserPermissions = array('read_stream', 'user_photos');
|
||||
|
||||
public static function initialize()
|
||||
{
|
||||
if (!strlen(FacebookTestCredentials::$appId) ||
|
||||
!strlen(FacebookTestCredentials::$appSecret)) {
|
||||
throw new FacebookSDKException(
|
||||
'You must fill out FacebookTestCredentials.php'
|
||||
);
|
||||
}
|
||||
FacebookSession::setDefaultApplication(
|
||||
FacebookTestCredentials::$appId, FacebookTestCredentials::$appSecret
|
||||
);
|
||||
if (!static::$testSession instanceof FacebookSession) {
|
||||
static::$testSession = static::createTestSession();
|
||||
}
|
||||
}
|
||||
|
||||
public static function createTestSession()
|
||||
{
|
||||
static::createTestUserAndGetAccessToken();
|
||||
return new FacebookSession(static::$testUserAccessToken);
|
||||
}
|
||||
|
||||
public static function createTestUserAndGetAccessToken()
|
||||
{
|
||||
$testUserPath = '/' . FacebookTestCredentials::$appId . '/accounts/test-users';
|
||||
$params = array(
|
||||
'installed' => true,
|
||||
'name' => 'Foo Phpunit User',
|
||||
'locale' => 'en_US',
|
||||
'permissions' => implode(',', static::$testUserPermissions),
|
||||
);
|
||||
|
||||
$request = new FacebookRequest(static::getAppSession(), 'POST', $testUserPath, $params);
|
||||
$response = $request->execute()->getGraphObject();
|
||||
|
||||
static::$testUserId = $response->getProperty('id');
|
||||
static::$testUserAccessToken = $response->getProperty('access_token');
|
||||
}
|
||||
|
||||
public static function getAppSession()
|
||||
{
|
||||
return new FacebookSession(static::getAppToken());
|
||||
}
|
||||
|
||||
public static function getAppToken()
|
||||
{
|
||||
return FacebookTestCredentials::$appId . '|' . FacebookTestCredentials::$appSecret;
|
||||
}
|
||||
|
||||
public static function deleteTestUser()
|
||||
{
|
||||
if (!static::$testUserId) {
|
||||
return;
|
||||
}
|
||||
$testUserPath = '/' . static::$testUserId;
|
||||
$request = new FacebookRequest(static::getAppSession(), 'DELETE', $testUserPath);
|
||||
$request->execute();
|
||||
}
|
||||
|
||||
}
|
53
external/facebook-sdk/tests/GraphAlbumTest.php
vendored
53
external/facebook-sdk/tests/GraphAlbumTest.php
vendored
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphAlbum;
|
||||
|
||||
class GraphAlbumTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
const ALBUM_DESCRIPTION = "Album Description";
|
||||
const ALBUM_NAME = "Album Name";
|
||||
|
||||
public function testMeReturnsGraphAlbum()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'POST',
|
||||
'/me/albums',
|
||||
array(
|
||||
'name' => self::ALBUM_NAME,
|
||||
'message' => self::ALBUM_DESCRIPTION,
|
||||
'value' => 'everyone'
|
||||
)
|
||||
))->execute()->getGraphObject();
|
||||
|
||||
$albumId = $response->getProperty('id');
|
||||
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/'.$albumId
|
||||
))->execute()->getGraphObject(GraphAlbum::className());
|
||||
|
||||
$this->assertTrue($response instanceof GraphAlbum);
|
||||
$this->assertEquals($albumId, $response->getId());
|
||||
$this->assertTrue($response->getFrom() instanceof \Facebook\GraphUser);
|
||||
$this->assertTrue($response->canUpload());
|
||||
$this->assertEquals(0, $response->getCount());
|
||||
$this->assertEquals(self::ALBUM_NAME, $response->getName());
|
||||
$this->assertEquals(self::ALBUM_DESCRIPTION, $response->getDescription());
|
||||
$this->assertNotNull($response->getLink());
|
||||
$this->assertNotNull($response->getPrivacy());
|
||||
|
||||
$type = array("profile", "mobile", "wall", "normal", "album");
|
||||
$this->assertTrue(in_array($response->getType(),$type));
|
||||
|
||||
date_default_timezone_set('GMT');
|
||||
$this->assertTrue($response->getCreatedTime() instanceof DateTime);
|
||||
$this->assertTrue($response->getUpdatedTime() instanceof DateTime);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphLocation;
|
||||
use Facebook\GraphObject;
|
||||
|
||||
class GraphLocationTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testLocation()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/104048449631599'
|
||||
))->execute()->getGraphObject();
|
||||
$this->assertTrue($response instanceof GraphObject);
|
||||
|
||||
$location = $response->getProperty('location', GraphLocation::className());
|
||||
$this->assertTrue(is_float($location->getLatitude()));
|
||||
$this->assertTrue(is_float($location->getLongitude()));
|
||||
}
|
||||
|
||||
}
|
97
external/facebook-sdk/tests/GraphObjectTest.php
vendored
97
external/facebook-sdk/tests/GraphObjectTest.php
vendored
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphObject;
|
||||
use Facebook\FacebookResponse;
|
||||
use Facebook\GraphUser;
|
||||
|
||||
class GraphObjectTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testFriends()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/me/friends'
|
||||
))->execute()->getGraphObjectList();
|
||||
$this->assertTrue(is_array($response));
|
||||
}
|
||||
|
||||
public function testArrayProperties()
|
||||
{
|
||||
$backingData = array(
|
||||
'id' => 42,
|
||||
'friends' => array(
|
||||
'data' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => 'David'
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'name' => 'Fosco'
|
||||
)
|
||||
),
|
||||
'paging' => array(
|
||||
'next' => 'nexturl'
|
||||
)
|
||||
)
|
||||
);
|
||||
$obj = new GraphObject($backingData);
|
||||
$friends = $obj->getPropertyAsArray('friends');
|
||||
$this->assertEquals(2, count($friends));
|
||||
$this->assertTrue($friends[0] instanceof GraphObject);
|
||||
$this->assertTrue($friends[1] instanceof GraphObject);
|
||||
$this->assertEquals('David', $friends[0]->getProperty('name'));
|
||||
$this->assertEquals('Fosco', $friends[1]->getProperty('name'));
|
||||
|
||||
$backingData = array(
|
||||
'id' => 42,
|
||||
'friends' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => 'Ilya'
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'name' => 'Kevin'
|
||||
)
|
||||
)
|
||||
);
|
||||
$obj = new GraphObject($backingData);
|
||||
$friends = $obj->getPropertyAsArray('friends');
|
||||
$this->assertEquals(2, count($friends));
|
||||
$this->assertTrue($friends[0] instanceof GraphObject);
|
||||
$this->assertTrue($friends[1] instanceof GraphObject);
|
||||
$this->assertEquals('Ilya', $friends[0]->getProperty('name'));
|
||||
$this->assertEquals('Kevin', $friends[1]->getProperty('name'));
|
||||
|
||||
}
|
||||
|
||||
public function testAsList()
|
||||
{
|
||||
$backingData = array(
|
||||
'data' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => 'David'
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'name' => 'Fosco'
|
||||
)
|
||||
)
|
||||
);
|
||||
$enc = json_encode($backingData);
|
||||
$response = new FacebookResponse(null, json_decode($enc), $enc);
|
||||
$list = $response->getGraphObjectList(GraphUser::className());
|
||||
$this->assertEquals(2, count($list));
|
||||
$this->assertTrue($list[0] instanceof GraphObject);
|
||||
$this->assertTrue($list[1] instanceof GraphObject);
|
||||
$this->assertEquals('David', $list[0]->getName());
|
||||
$this->assertEquals('Fosco', $list[1]->getName());
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\GraphSessionInfo;
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\FacebookSession;
|
||||
|
||||
class GraphSessionInfoTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testSessionInfo()
|
||||
{
|
||||
$params = array(
|
||||
'input_token' => FacebookTestHelper::$testSession->getToken()
|
||||
);
|
||||
$response = (new FacebookRequest(
|
||||
new FacebookSession(FacebookTestHelper::getAppToken()),
|
||||
'GET',
|
||||
'/debug_token',
|
||||
$params
|
||||
))->execute()->getGraphObject(GraphSessionInfo::className());
|
||||
$this->assertTrue($response instanceof GraphSessionInfo);
|
||||
$this->assertNotNull($response->getAppId());
|
||||
$this->assertTrue($response->isValid());
|
||||
}
|
||||
|
||||
}
|
27
external/facebook-sdk/tests/GraphUserTest.php
vendored
27
external/facebook-sdk/tests/GraphUserTest.php
vendored
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Facebook\FacebookRequest;
|
||||
use Facebook\GraphUser;
|
||||
|
||||
class GraphUserTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testMeReturnsGraphUser()
|
||||
{
|
||||
$response = (
|
||||
new FacebookRequest(
|
||||
FacebookTestHelper::$testSession,
|
||||
'GET',
|
||||
'/me'
|
||||
))->execute()->getGraphObject(GraphUser::className());
|
||||
|
||||
$info = FacebookTestHelper::$testSession->getSessionInfo();
|
||||
|
||||
$this->assertTrue($response instanceof GraphUser);
|
||||
$this->assertEquals($info->getId(), $response->getId());
|
||||
$this->assertNotNull($response->getName());
|
||||
$this->assertNotNull($response->getLastName());
|
||||
$this->assertNotNull($response->getLink());
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
abstract class AbstractTestHttpClient extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $fakeRawRedirectHeader = "HTTP/1.1 302 Found
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Location: https://foobar.com/\r\n\r\n";
|
||||
protected $fakeRawProxyHeader = "HTTP/1.0 200 Connection established\r\n\r\n";
|
||||
protected $fakeRawProxyHeader2 = "HTTP/1.0 200 Connection established
|
||||
Proxy-agent: Kerio Control/7.1.1 build 1971\r\n\r\n";
|
||||
protected $fakeRawHeader = "HTTP/1.1 200 OK
|
||||
Etag: \"9d86b21aa74d74e574bbb35ba13524a52deb96e3\"
|
||||
Content-Type: text/javascript; charset=UTF-8
|
||||
X-FB-Rev: 9244768
|
||||
Pragma: no-cache
|
||||
Expires: Sat, 01 Jan 2000 00:00:00 GMT
|
||||
Connection: close
|
||||
Date: Mon, 19 May 2014 18:37:17 GMT
|
||||
X-FB-Debug: 02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=
|
||||
Content-Length: 29
|
||||
Cache-Control: private, no-cache, no-store, must-revalidate
|
||||
Access-Control-Allow-Origin: *\r\n\r\n";
|
||||
protected $fakeRawBody = "{\"id\":\"123\",\"name\":\"Foo Bar\"}";
|
||||
protected $fakeHeadersAsArray = array(
|
||||
'http_code' => 'HTTP/1.1 200 OK',
|
||||
'Etag' => '"9d86b21aa74d74e574bbb35ba13524a52deb96e3"',
|
||||
'Content-Type' => 'text/javascript; charset=UTF-8',
|
||||
'X-FB-Rev' => '9244768',
|
||||
'Pragma' => 'no-cache',
|
||||
'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT',
|
||||
'Connection' => 'close',
|
||||
'Date' => 'Mon, 19 May 2014 18:37:17 GMT',
|
||||
'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=',
|
||||
'Content-Length' => '29',
|
||||
'Cache-Control' => 'private, no-cache, no-store, must-revalidate',
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
);
|
||||
|
||||
}
|
@ -1,439 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/AbstractTestHttpClient.php';
|
||||
|
||||
use Mockery as m;
|
||||
use Facebook\HttpClients\FacebookCurlHttpClient;
|
||||
|
||||
class FacebookCurlHttpClientTest extends AbstractTestHttpClient
|
||||
{
|
||||
|
||||
protected $curlMock;
|
||||
protected $curlClient;
|
||||
|
||||
const CURL_VERSION_STABLE = 0x072400;
|
||||
const CURL_VERSION_BUGGY = 0x071400;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->curlMock = m::mock('Facebook\HttpClients\FacebookCurl');
|
||||
$this->curlClient = new FacebookCurlHttpClient($this->curlMock);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
(new FacebookCurlHttpClient()); // Resets the static dependency injection
|
||||
}
|
||||
|
||||
public function testCanOpenGetCurlConnection()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->with(array(
|
||||
CURLOPT_URL => 'http://foo.com',
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
))
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->openConnection('http://foo.com', 'GET', array());
|
||||
}
|
||||
|
||||
public function testCanOpenGetCurlConnectionWithHeaders()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->with(array(
|
||||
CURLOPT_URL => 'http://foo.com',
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'X-foo: bar',
|
||||
),
|
||||
))
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->addRequestHeader('X-foo', 'bar');
|
||||
$this->curlClient->openConnection('http://foo.com', 'GET', array());
|
||||
}
|
||||
|
||||
public function testCanOpenPostCurlConnection()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->with(array(
|
||||
CURLOPT_URL => 'http://bar.com',
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
'baz' => 'bar',
|
||||
),
|
||||
))
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->openConnection('http://bar.com', 'POST', array('baz' => 'bar'));
|
||||
}
|
||||
|
||||
public function testCanOpenPutCurlConnection()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->with(array(
|
||||
CURLOPT_URL => 'http://baz.com',
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_CUSTOMREQUEST => 'PUT',
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
'baz' => 'bar',
|
||||
),
|
||||
))
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->openConnection('http://baz.com', 'PUT', array('baz' => 'bar'));
|
||||
}
|
||||
|
||||
public function testCanOpenDeleteCurlConnection()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->with(array(
|
||||
CURLOPT_URL => 'http://faz.com',
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_CUSTOMREQUEST => 'DELETE',
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
'baz' => 'bar',
|
||||
),
|
||||
))
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->openConnection('http://faz.com', 'DELETE', array('baz' => 'bar'));
|
||||
}
|
||||
|
||||
public function testCanAddBundledCert()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt')
|
||||
->with(CURLOPT_CAINFO, '/.fb_ca_chain_bundle\.crt$/')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->addBundledCert();
|
||||
}
|
||||
|
||||
public function testCanCloseConnection()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('close')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->closeConnection();
|
||||
}
|
||||
|
||||
public function testTrySendRequest()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn('foo response');
|
||||
$this->curlMock
|
||||
->shouldReceive('errno')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('error')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HTTP_CODE)
|
||||
->once()
|
||||
->andReturn(200);
|
||||
|
||||
$this->curlClient->tryToSendRequest();
|
||||
}
|
||||
|
||||
public function testProperlyCompilesRequestHeaders()
|
||||
{
|
||||
$headers = $this->curlClient->compileRequestHeaders();
|
||||
$expectedHeaders = array();
|
||||
$this->assertEquals($expectedHeaders, $headers);
|
||||
|
||||
$this->curlClient->addRequestHeader('X-foo', 'bar');
|
||||
$headers = $this->curlClient->compileRequestHeaders();
|
||||
$expectedHeaders = array(
|
||||
'X-foo: bar',
|
||||
);
|
||||
$this->assertEquals($expectedHeaders, $headers);
|
||||
|
||||
$this->curlClient->addRequestHeader('X-bar', 'baz');
|
||||
$headers = $this->curlClient->compileRequestHeaders();
|
||||
$expectedHeaders = array(
|
||||
'X-foo: bar',
|
||||
'X-bar: baz',
|
||||
);
|
||||
$this->assertEquals($expectedHeaders, $headers);
|
||||
}
|
||||
|
||||
public function testIsolatesTheHeaderAndBody()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HEADER_SIZE)
|
||||
->once()
|
||||
->andReturn(strlen($this->fakeRawHeader));
|
||||
$this->curlMock
|
||||
->shouldReceive('version')
|
||||
->once()
|
||||
->andReturn(array('version_number' => self::CURL_VERSION_STABLE));
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn($this->fakeRawHeader . $this->fakeRawBody);
|
||||
|
||||
$this->curlClient->sendRequest();
|
||||
list($rawHeader, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
|
||||
|
||||
$this->assertEquals($rawHeader, trim($this->fakeRawHeader));
|
||||
$this->assertEquals($rawBody, $this->fakeRawBody);
|
||||
}
|
||||
|
||||
public function testConvertsRawHeadersToArray()
|
||||
{
|
||||
$headers = FacebookCurlHttpClient::headersToArray($this->fakeRawHeader);
|
||||
|
||||
$this->assertEquals($headers, $this->fakeHeadersAsArray);
|
||||
}
|
||||
|
||||
public function testProperlyHandlesProxyHeaders()
|
||||
{
|
||||
$rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader;
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HEADER_SIZE)
|
||||
->once()
|
||||
->andReturn(mb_strlen($rawHeader));
|
||||
$this->curlMock
|
||||
->shouldReceive('version')
|
||||
->once()
|
||||
->andReturn(array('version_number' => self::CURL_VERSION_STABLE));
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn($rawHeader . $this->fakeRawBody);
|
||||
|
||||
$this->curlClient->sendRequest();
|
||||
list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
|
||||
|
||||
$this->assertEquals($rawHeaders, trim($rawHeader));
|
||||
$this->assertEquals($rawBody, $this->fakeRawBody);
|
||||
|
||||
$headers = FacebookCurlHttpClient::headersToArray($rawHeaders);
|
||||
|
||||
$this->assertEquals($headers, $this->fakeHeadersAsArray);
|
||||
}
|
||||
|
||||
public function testProperlyHandlesProxyHeadersWithCurlBug()
|
||||
{
|
||||
$rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader;
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HEADER_SIZE)
|
||||
->once()
|
||||
->andReturn(mb_strlen($this->fakeRawHeader)); // Mimic bug that doesn't count proxy header
|
||||
$this->curlMock
|
||||
->shouldReceive('version')
|
||||
->once()
|
||||
->andReturn(array('version_number' => self::CURL_VERSION_BUGGY));
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn($rawHeader . $this->fakeRawBody);
|
||||
|
||||
$this->curlClient->sendRequest();
|
||||
list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
|
||||
|
||||
$this->assertEquals($rawHeaders, trim($rawHeader));
|
||||
$this->assertEquals($rawBody, $this->fakeRawBody);
|
||||
|
||||
$headers = FacebookCurlHttpClient::headersToArray($rawHeaders);
|
||||
|
||||
$this->assertEquals($headers, $this->fakeHeadersAsArray);
|
||||
}
|
||||
|
||||
public function testProperlyHandlesProxyHeadersWithCurlBug2()
|
||||
{
|
||||
$rawHeader = $this->fakeRawProxyHeader2 . $this->fakeRawHeader;
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HEADER_SIZE)
|
||||
->once()
|
||||
->andReturn(mb_strlen($this->fakeRawHeader)); // Mimic bug that doesn't count proxy header
|
||||
$this->curlMock
|
||||
->shouldReceive('version')
|
||||
->once()
|
||||
->andReturn(array('version_number' => self::CURL_VERSION_BUGGY));
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn($rawHeader . $this->fakeRawBody);
|
||||
|
||||
$this->curlClient->sendRequest();
|
||||
list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
|
||||
|
||||
$this->assertEquals($rawHeaders, trim($rawHeader));
|
||||
$this->assertEquals($rawBody, $this->fakeRawBody);
|
||||
|
||||
$headers = FacebookCurlHttpClient::headersToArray($rawHeaders);
|
||||
|
||||
$this->assertEquals($headers, $this->fakeHeadersAsArray);
|
||||
}
|
||||
|
||||
public function testProperlyHandlesRedirectHeaders()
|
||||
{
|
||||
$rawHeader = $this->fakeRawRedirectHeader . $this->fakeRawHeader;
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HEADER_SIZE)
|
||||
->once()
|
||||
->andReturn(mb_strlen($rawHeader));
|
||||
$this->curlMock
|
||||
->shouldReceive('version')
|
||||
->once()
|
||||
->andReturn(array('version_number' => self::CURL_VERSION_STABLE));
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn($rawHeader . $this->fakeRawBody);
|
||||
|
||||
$this->curlClient->sendRequest();
|
||||
list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
|
||||
|
||||
$this->assertEquals($rawHeaders, trim($rawHeader));
|
||||
$this->assertEquals($rawBody, $this->fakeRawBody);
|
||||
|
||||
$headers = FacebookCurlHttpClient::headersToArray($rawHeaders);
|
||||
|
||||
$this->assertEquals($headers, $this->fakeHeadersAsArray);
|
||||
}
|
||||
|
||||
public function testCanSendNormalRequest()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn($this->fakeRawHeader . $this->fakeRawBody);
|
||||
$this->curlMock
|
||||
->shouldReceive('errno')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('error')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HTTP_CODE)
|
||||
->once()
|
||||
->andReturn(200);
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HEADER_SIZE)
|
||||
->once()
|
||||
->andReturn(mb_strlen($this->fakeRawHeader));
|
||||
$this->curlMock
|
||||
->shouldReceive('version')
|
||||
->once()
|
||||
->andReturn(array('version_number' => self::CURL_VERSION_STABLE));
|
||||
$this->curlMock
|
||||
->shouldReceive('close')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$responseBody = $this->curlClient->send('http://foo.com/');
|
||||
|
||||
$this->assertEquals($responseBody, $this->fakeRawBody);
|
||||
$this->assertEquals($this->curlClient->getResponseHeaders(), $this->fakeHeadersAsArray);
|
||||
$this->assertEquals(200, $this->curlClient->getResponseHttpStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testThrowsExceptionOnClientError()
|
||||
{
|
||||
$this->curlMock
|
||||
->shouldReceive('init')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('setopt_array')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->curlMock
|
||||
->shouldReceive('exec')
|
||||
->once()
|
||||
->andReturn(false);
|
||||
$this->curlMock
|
||||
->shouldReceive('errno')
|
||||
->once()
|
||||
->andReturn(123);
|
||||
$this->curlMock
|
||||
->shouldReceive('error')
|
||||
->once()
|
||||
->andReturn('Foo error');
|
||||
$this->curlMock
|
||||
->shouldReceive('getinfo')
|
||||
->with(CURLINFO_HTTP_CODE)
|
||||
->once()
|
||||
->andReturn(null);
|
||||
|
||||
$this->curlClient->send('http://foo.com/');
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/AbstractTestHttpClient.php';
|
||||
|
||||
use Mockery as m;
|
||||
use Facebook\HttpClients\FacebookGuzzleHttpClient;
|
||||
|
||||
class FacebookGuzzleHttpClientTest extends AbstractTestHttpClient
|
||||
{
|
||||
|
||||
protected $guzzleMock;
|
||||
protected $guzzleClient;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->guzzleMock = m::mock('GuzzleHttp\Client');
|
||||
$this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
(new FacebookGuzzleHttpClient()); // Resets the static dependency injection
|
||||
}
|
||||
|
||||
public function testCanSendNormalRequest()
|
||||
{
|
||||
$requestMock = m::mock('GuzzleHttp\Message\RequestInterface');
|
||||
$requestMock
|
||||
->shouldReceive('setHeader')
|
||||
->once()
|
||||
->with('X-foo', 'bar')
|
||||
->andReturn(null);
|
||||
|
||||
$responseMock = m::mock('GuzzleHttp\Message\ResponseInterface');
|
||||
$responseMock
|
||||
->shouldReceive('getStatusCode')
|
||||
->once()
|
||||
->andReturn(200);
|
||||
$responseMock
|
||||
->shouldReceive('getHeaders')
|
||||
->once()
|
||||
->andReturn($this->fakeHeadersAsArray);
|
||||
$responseMock
|
||||
->shouldReceive('getBody')
|
||||
->once()
|
||||
->andReturn($this->fakeRawBody);
|
||||
|
||||
$this->guzzleMock
|
||||
->shouldReceive('createRequest')
|
||||
->once()
|
||||
->with('GET', 'http://foo.com/', array())
|
||||
->andReturn($requestMock);
|
||||
$this->guzzleMock
|
||||
->shouldReceive('send')
|
||||
->once()
|
||||
->with($requestMock)
|
||||
->andReturn($responseMock);
|
||||
|
||||
$this->guzzleClient->addRequestHeader('X-foo', 'bar');
|
||||
$responseBody = $this->guzzleClient->send('http://foo.com/');
|
||||
|
||||
$this->assertEquals($responseBody, $this->fakeRawBody);
|
||||
$this->assertEquals($this->guzzleClient->getResponseHeaders(), $this->fakeHeadersAsArray);
|
||||
$this->assertEquals(200, $this->guzzleClient->getResponseHttpStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testThrowsExceptionOnClientError()
|
||||
{
|
||||
$requestMock = m::mock('GuzzleHttp\Message\RequestInterface');
|
||||
$exceptionMock = m::mock(
|
||||
'GuzzleHttp\Exception\RequestException',
|
||||
array(
|
||||
'Foo Error',
|
||||
$requestMock,
|
||||
null,
|
||||
m::mock('GuzzleHttp\Exception\AdapterException'),
|
||||
));
|
||||
|
||||
$this->guzzleMock
|
||||
->shouldReceive('createRequest')
|
||||
->once()
|
||||
->with('GET', 'http://foo.com/', array())
|
||||
->andReturn($requestMock);
|
||||
$this->guzzleMock
|
||||
->shouldReceive('send')
|
||||
->once()
|
||||
->with($requestMock)
|
||||
->andThrow($exceptionMock);
|
||||
|
||||
$this->guzzleClient->send('http://foo.com/');
|
||||
}
|
||||
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/AbstractTestHttpClient.php';
|
||||
|
||||
use Mockery as m;
|
||||
use Facebook\HttpClients\FacebookStreamHttpClient;
|
||||
|
||||
class FacebookStreamHttpClientTest extends AbstractTestHttpClient
|
||||
{
|
||||
|
||||
protected $streamMock;
|
||||
protected $streamClient;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->streamMock = m::mock('Facebook\HttpClients\FacebookStream');
|
||||
$this->streamClient = new FacebookStreamHttpClient($this->streamMock);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
(new FacebookStreamHttpClient()); // Resets the static dependency injection
|
||||
}
|
||||
|
||||
public function testCanCompileHeader()
|
||||
{
|
||||
$this->streamClient->addRequestHeader('X-foo', 'bar');
|
||||
$this->streamClient->addRequestHeader('X-bar', 'faz');
|
||||
$header = $this->streamClient->compileHeader();
|
||||
$this->assertEquals("X-foo: bar\r\nX-bar: faz", $header);
|
||||
}
|
||||
|
||||
public function testCanFormatHeadersToArray()
|
||||
{
|
||||
$raw_header_array = explode("\n", trim($this->fakeRawHeader));
|
||||
$header_array = FacebookStreamHttpClient::formatHeadersToArray($raw_header_array);
|
||||
$this->assertEquals($this->fakeHeadersAsArray, $header_array);
|
||||
}
|
||||
|
||||
public function testCanGetHttpStatusCodeFromResponseHeader()
|
||||
{
|
||||
$http_code = FacebookStreamHttpClient::getStatusCodeFromHeader('HTTP/1.1 123 Foo Response');
|
||||
$this->assertEquals('123', $http_code);
|
||||
}
|
||||
|
||||
public function testCanSendNormalRequest()
|
||||
{
|
||||
$this->streamMock
|
||||
->shouldReceive('streamContextCreate')
|
||||
->once()
|
||||
->with(\Mockery::on(function($arg) {
|
||||
if (!isset($arg['http']) || !isset($arg['ssl'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($arg['http'] !== array(
|
||||
'method' => 'GET',
|
||||
'timeout' => 60,
|
||||
'ignore_errors' => true,
|
||||
'header' => 'X-foo: bar',
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($arg['ssl']['verify_peer'] !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false === preg_match('/.fb_ca_chain_bundle\.crt$/', $arg['ssl']['cafile'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}))
|
||||
->andReturn(null);
|
||||
$this->streamMock
|
||||
->shouldReceive('getResponseHeaders')
|
||||
->once()
|
||||
->andReturn(explode("\n", trim($this->fakeRawHeader)));
|
||||
$this->streamMock
|
||||
->shouldReceive('fileGetContents')
|
||||
->once()
|
||||
->with('http://foo.com/')
|
||||
->andReturn($this->fakeRawBody);
|
||||
|
||||
$this->streamClient->addRequestHeader('X-foo', 'bar');
|
||||
$responseBody = $this->streamClient->send('http://foo.com/');
|
||||
|
||||
$this->assertEquals($responseBody, $this->fakeRawBody);
|
||||
$this->assertEquals($this->streamClient->getResponseHeaders(), $this->fakeHeadersAsArray);
|
||||
$this->assertEquals(200, $this->streamClient->getResponseHttpStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Facebook\FacebookSDKException
|
||||
*/
|
||||
public function testThrowsExceptionOnClientError()
|
||||
{
|
||||
$this->streamMock
|
||||
->shouldReceive('streamContextCreate')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->streamMock
|
||||
->shouldReceive('getResponseHeaders')
|
||||
->once()
|
||||
->andReturn(null);
|
||||
$this->streamMock
|
||||
->shouldReceive('fileGetContents')
|
||||
->once()
|
||||
->with('http://foo.com/')
|
||||
->andReturn(false);
|
||||
|
||||
$this->streamClient->send('http://foo.com/');
|
||||
}
|
||||
|
||||
}
|
35
external/facebook-sdk/tests/bootstrap.php
vendored
35
external/facebook-sdk/tests/bootstrap.php
vendored
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Facebook\FacebookSDKException;
|
||||
|
||||
if (!file_exists(__DIR__ . '/FacebookTestCredentials.php')) {
|
||||
throw new FacebookSDKException(
|
||||
'You must create a FacebookTestCredentials.php file from FacebookTestCredentials.php.dist'
|
||||
);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/FacebookTestCredentials.php';
|
||||
require_once __DIR__ . '/FacebookTestHelper.php';
|
||||
|
||||
// Uncomment two lines to force functional test curl implementation
|
||||
//use Facebook\HttpClients\FacebookCurlHttpClient;
|
||||
//FacebookRequest::setHttpClientHandler(new FacebookCurlHttpClient());
|
||||
|
||||
// Uncomment two lines to force functional test stream wrapper implementation
|
||||
//use Facebook\HttpClients\FacebookStreamHttpClient;
|
||||
//FacebookRequest::setHttpClientHandler(new FacebookStreamHttpClient());
|
||||
|
||||
// Uncomment two lines to force functional test Guzzle implementation
|
||||
//use Facebook\HttpClients\FacebookGuzzleHttpClient;
|
||||
//FacebookRequest::setHttpClientHandler(new FacebookGuzzleHttpClient());
|
||||
|
||||
// Create a temp test user to use for testing
|
||||
FacebookTestHelper::initialize();
|
||||
|
||||
// Delete the temp test user after all tests have fired
|
||||
register_shutdown_function(function ()
|
||||
{
|
||||
FacebookTestHelper::deleteTestUser();
|
||||
});
|
10
plugin.ini
10
plugin.ini
@ -1,7 +1,7 @@
|
||||
[Plugin description]
|
||||
name = "Facebook"
|
||||
name = "Diaspora"
|
||||
version = 0.1
|
||||
author = "Ben Werdmuller"
|
||||
author_email = "ben@benwerd.com"
|
||||
author_url = "http://werd.io"
|
||||
description = "Cross-post site content to Facebook. Contains the <a href=\"https://github.com/facebook/facebook-php-sdk\">PHP Facebook SDK</a>."
|
||||
author = "Lucas Verney (Phyks)"
|
||||
author_email = "phyks@phyks.me"
|
||||
author_url = "http://phyks.me"
|
||||
description = "Cross-post site content to Diaspora."
|
||||
|
Loading…
Reference in New Issue
Block a user