Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 86c6074

Browse files
committed
Remove helpers
1 parent 7cc23a4 commit 86c6074

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+30
-3153
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Starting with version 5, the Facebook PHP SDK follows [SemVer](http://semver.org
1111
- Replace custom CSPRNG implementation with `paragonie/random_compat` (#644)
1212
- Removed the built-in autoloader in favor of composer's autoloader (#646)
1313
- Big integers in signed requests get decoded as `string` instead of `float` (#699)
14+
- Remove helpers
1415

1516
## 5.x
1617

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ $fb = new \Facebook\Facebook([
3333
//'default_access_token' => '{access-token}', // optional
3434
]);
3535

36-
// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
37-
// $helper = $fb->getRedirectLoginHelper();
38-
// $helper = $fb->getJavaScriptHelper();
39-
// $helper = $fb->getCanvasHelper();
40-
// $helper = $fb->getPageTabHelper();
41-
4236
try {
4337
// Get the \Facebook\GraphNodes\GraphUser object for the current user.
4438
// If you provided a 'default_access_token', the '{access-token}' is optional.

docs/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ For installation & implementation instructions, look through the [Getting Starte
1313
The following examples demonstrate how you would accomplish common tasks with the Facebook SDK for PHP.
1414

1515
- **Authentication & Signed Requests**
16-
- [Facebook Login (OAuth 2.0)](./examples/facebook_login.md)
1716
- [Obtaining an access token from the SDK for JavaScript](./examples/access_token_from_javascript.md)
1817
- [Obtaining an access token within a Facebook Canvas context](./examples/access_token_from_canvas.md)
1918
- [Obtaining an access token within a Facebook Page tab context](./examples/access_token_from_page_tab.md)

docs/examples/access_token_from_canvas.md

+13-18
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,32 @@ This example covers obtaining an access token and signed request from within the
44

55
## Example
66

7-
A signed request will be sent to your app via the HTTP POST method within the context of app canvas. The PHP SDK provides a helper to easily obtain, validate & decode the signed request. If the proper OAuth data exists in the signed request payload data, an attempt can be made to obtain an access token from the Graph API.
7+
A signed request will be sent to your app via the HTTP POST method within the context of app canvas. The PHP SDK provides a helper to validate & decode the signed request.
88

99
```php
1010
$fb = new Facebook\Facebook([
11-
'app_id' => '{app-id}',
12-
'app_secret' => '{app-secret}',
13-
'default_graph_version' => 'v2.9',
14-
]);
15-
16-
$helper = $fb->getCanvasHelper();
11+
'app_id' => '{app-id}',
12+
'app_secret' => '{app-secret}',
13+
'default_graph_version' => 'v2.9',
14+
]);
1715

1816
try {
19-
$accessToken = $helper->getAccessToken();
20-
} catch(Facebook\Exceptions\FacebookResponseException $e) {
21-
// When Graph returns an error
22-
echo 'Graph returned an error: ' . $e->getMessage();
23-
exit;
17+
$signedRequest = new SignedRequest($fb->getApp(), $_POST['signed_request'])
18+
$accessToken = $signedRequest->getAccessToken();
2419
} catch(Facebook\Exceptions\FacebookSDKException $e) {
25-
// When validation fails or other local issues
26-
echo 'Facebook SDK returned an error: ' . $e->getMessage();
27-
exit;
20+
// When validation fails or other local issues
21+
echo 'Facebook SDK returned an error: ' . $e->getMessage();
22+
exit;
2823
}
2924

3025
if (! isset($accessToken)) {
31-
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
32-
exit;
26+
echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
27+
exit;
3328
}
3429

3530
// Logged in
3631
echo '<h3>Signed Request</h3>';
37-
var_dump($helper->getSignedRequest());
32+
var_dump($signedRequest->getPayload());
3833

3934
echo '<h3>Access Token</h3>';
4035
var_dump($accessToken->getValue());

docs/examples/access_token_from_javascript.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,24 @@ After the user successfully logs in, redirect the user (or make an AJAX request)
5050
```php
5151
# /js-login.php
5252
$fb = new Facebook\Facebook([
53-
'app_id' => '{app-id}',
54-
'app_secret' => '{app-secret}',
55-
'default_graph_version' => 'v2.9',
56-
]);
57-
58-
$helper = $fb->getJavaScriptHelper();
53+
'app_id' => '{app-id}',
54+
'app_secret' => '{app-secret}',
55+
'default_graph_version' => 'v2.9',
56+
]);
5957

6058
try {
61-
$accessToken = $helper->getAccessToken();
62-
} catch(Facebook\Exceptions\FacebookResponseException $e) {
63-
// When Graph returns an error
64-
echo 'Graph returned an error: ' . $e->getMessage();
65-
exit;
59+
$fbApp = $fb->getApp();
60+
$signedRequest = new SignedRequest($fbApp, $_COOKIE['fbsr_' . $fbApp->getId()]))
61+
$accessToken = $signedRequest->getAccessToken();
6662
} catch(Facebook\Exceptions\FacebookSDKException $e) {
67-
// When validation fails or other local issues
68-
echo 'Facebook SDK returned an error: ' . $e->getMessage();
69-
exit;
63+
// When validation fails or other local issues
64+
echo 'Facebook SDK returned an error: ' . $e->getMessage();
65+
exit;
7066
}
7167

7268
if (! isset($accessToken)) {
73-
echo 'No cookie set or no OAuth data could be obtained from cookie.';
74-
exit;
69+
echo 'No cookie set or no OAuth data could be obtained from cookie.';
70+
exit;
7571
}
7672

7773
// Logged in

docs/examples/access_token_from_page_tab.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- @TODO: Rewrite doc -->
12
# Get Access Token From Page Tab Example
23

34
This example covers obtaining an access token and signed request from within the context of a page tab with the Facebook SDK for PHP.

docs/examples/facebook_login.md

-101
This file was deleted.

docs/getting_started.md

+3-101
Original file line numberDiff line numberDiff line change
@@ -50,113 +50,15 @@ The `Facebook\Facebook` service ties all the components of the SDK for PHP toget
5050

5151
The SDK can be used to support logging a Facebook user into your site using Facebook Login which is based on OAuth 2.0.
5252

53-
Most all request made to the Graph API require an access token. We can obtain user access tokens with the SDK using the [helper classes](reference.md).
54-
55-
56-
### Obtaining an access token from redirect
57-
58-
For most websites, you'll use the [`Facebook\Helpers\FacebookRedirectLoginHelper`](reference/FacebookRedirectLoginHelper.md) to generate a login URL with the `getLoginUrl()` method. The link will take the user to an app authorization screen and upon approval, will redirect them back to a URL that you specified. On the redirect callback page we can obtain the user access token as an [`AccessToken`](reference/AccessToken.md) entity.
59-
60-
> For this example we'll assume `login.php` will present the login link and the user will be redirected to `login-callback.php` where we will obtain the access token.
61-
62-
```php
63-
# login.php
64-
$fb = new Facebook\Facebook([/* . . . */]);
65-
66-
$helper = $fb->getRedirectLoginHelper();
67-
$permissions = ['email', 'user_likes']; // optional
68-
$loginUrl = $helper->getLoginUrl('http://{your-website}/login-callback.php', $permissions);
69-
70-
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
71-
```
72-
73-
> **Warning:** The `FacebookRedirectLoginHelper` makes use of sessions to store a [CSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) value. You need to make sure you have sessions enabled before invoking the `getLoginUrl()` method. This is usually done automatically in most web frameworks, but if you're not using a web framework you can add [`session_start();`](http://php.net/session_start) to the top of your `login.php` & `login-callback.php` scripts.
74-
75-
```php
76-
# login-callback.php
77-
$fb = new Facebook\Facebook([/* . . . */]);
78-
79-
$helper = $fb->getRedirectLoginHelper();
80-
try {
81-
$accessToken = $helper->getAccessToken();
82-
} catch(Facebook\Exceptions\FacebookResponseException $e) {
83-
// When Graph returns an error
84-
echo 'Graph returned an error: ' . $e->getMessage();
85-
exit;
86-
} catch(Facebook\Exceptions\FacebookSDKException $e) {
87-
// When validation fails or other local issues
88-
echo 'Facebook SDK returned an error: ' . $e->getMessage();
89-
exit;
90-
}
91-
92-
if (isset($accessToken)) {
93-
// Logged in!
94-
$_SESSION['facebook_access_token'] = (string) $accessToken;
95-
96-
// Now you can redirect to another page and use the
97-
// access token from $_SESSION['facebook_access_token']
98-
}
99-
```
100-
53+
Most all request made to the Graph API require an access token. We can obtain user access tokens with libraries dedicated to OAuth 2.0.
10154

10255
### Obtaining an access token from a Facebook Canvas context
10356

104-
If your app is on Facebook Canvas, use the `getAccessToken()` method on [`Facebook\Helpers\FacebookCanvasHelper`](reference/FacebookCanvasHelper.md) to get an [`AccessToken`](reference/AccessToken.md) entity for the user.
105-
106-
> **Warning:** The `FacebookCanvasHelper` will detect a [signed request](reference.md#signed-requests) for you and attempt to obtain an access token using the payload data from the signed request. The signed request will only contain the data needed to obtain an access token if the user has already authorized your app sometime in the past. If they have not yet authorized your app the `getAccessToken()` will return `null` and you will need to log the user in with either the [redirect method](#obtaining-an-access-token-from-redirect) or by using the [SDK for JavaScript](https://developers.facebook.com/docs/javascript) and then use the SDK for PHP to [obtain the access token from the cookie](#obtaining-an-access-token-from-the-sdk-for-javascript) the SDK for JavaScript set.
107-
108-
```php
109-
# example-canvas-app.php
110-
$fb = new Facebook\Facebook([/* . . . */]);
111-
112-
$helper = $fb->getCanvasHelper();
113-
try {
114-
$accessToken = $helper->getAccessToken();
115-
} catch(Facebook\Exceptions\FacebookResponseException $e) {
116-
// When Graph returns an error
117-
echo 'Graph returned an error: ' . $e->getMessage();
118-
exit;
119-
} catch(Facebook\Exceptions\FacebookSDKException $e) {
120-
// When validation fails or other local issues
121-
echo 'Facebook SDK returned an error: ' . $e->getMessage();
122-
exit;
123-
}
124-
125-
if (isset($accessToken)) {
126-
// Logged in.
127-
}
128-
```
129-
130-
> If your app exists within the context of a Page tab, you can obtain an access token using the example above since a Page tab is very similar to a Facebook Canvas app. But if you'd like to use a Page-tab-specific helper, you can use the [`Facebook\Helpers\FacebookPageTabHelper`](reference/FacebookPageTabHelper.md)
131-
57+
**TODO**: Rewrite
13258

13359
### Obtaining an access token from the SDK for JavaScript
13460

135-
If you're already using the Facebook SDK for JavaScript to authenticate users, you can obtain the access token with PHP by using the [FacebookJavaScriptHelper](reference/FacebookJavaScriptHelper.md). The `getAccessToken()` method will return an [`AccessToken`](reference/AccessToken.md) entity.
136-
137-
```php
138-
# example-obtain-from-js-cookie-app.php
139-
$fb = new Facebook\Facebook([/* . . . */]);
140-
141-
$helper = $fb->getJavaScriptHelper();
142-
try {
143-
$accessToken = $helper->getAccessToken();
144-
} catch(Facebook\Exceptions\FacebookResponseException $e) {
145-
// When Graph returns an error
146-
echo 'Graph returned an error: ' . $e->getMessage();
147-
exit;
148-
} catch(Facebook\Exceptions\FacebookSDKException $e) {
149-
// When validation fails or other local issues
150-
echo 'Facebook SDK returned an error: ' . $e->getMessage();
151-
exit;
152-
}
153-
154-
if (isset($accessToken)) {
155-
// Logged in
156-
}
157-
```
158-
159-
> **Warning:** Make sure you set the `{cookie:true}` option when you [initialize the SDK for JavaScript](https://developers.facebook.com/docs/javascript/reference/FB.init/v2.9). This will make the SDK for JavaScript set a cookie on your domain containing information about the user in the form of a signed request.
61+
**TODO**: Rewrite
16062

16163
## Extending the access token
16264

docs/reference.md

-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ These classes facilitate authenticating a Facebook user with OAuth 2.0.
1717

1818
| Class name | Description |
1919
| ------------- | ------------- |
20-
| [`Facebook\Helpers\FacebookRedirectLoginHelper`](reference/FacebookRedirectLoginHelper.md) | An OAuth 2.0 service to obtain a user access token from a redirect using a "Log in with Facebook" link. |
2120
| [`Facebook\Authentication\AccessToken`](reference/AccessToken.md) | An entity that represents an access token. |
2221
| `Facebook\Authentication\AccessTokenMetadata` | An entity that represents metadata from an access token. |
2322
| `Facebook\Authentication\OAuth2Client` | An OAuth 2.0 client that sends and receives HTTP requests related to user authentication. |
@@ -41,9 +40,6 @@ Classes to help obtain and manage signed requests.
4140

4241
| Class name | Description |
4342
| ------------- | ------------- |
44-
| [`Facebook\Helpers\FacebookJavaScriptHelper`](reference/FacebookJavaScriptHelper.md) | Used to obtain an access token or signed request from the cookie set by the JavaScript SDK. |
45-
| [`Facebook\Helpers\FacebookCanvasHelper`](reference/FacebookCanvasHelper.md) | Used to obtain an access token or signed request from within the context of an app canvas. |
46-
| [`Facebook\Helpers\FacebookPageTabHelper`](reference/FacebookPageTabHelper.md) | Used to obtain an access token or signed request from within the context of a page tab. |
4743
| [`Facebook\SignedRequest`](reference/SignedRequest.md) | An entity that represents a signed request. |
4844

4945
# Core Exceptions
@@ -89,5 +85,3 @@ You can overwrite certain functionality of the SDK by coding to an interface and
8985
| ------------- | ------------- |
9086
| `Facebook\HttpClients\ FacebookHttpClientInterface` | An interface to code your own HTTP client implementation. |
9187
| `Facebook\Http\GraphRawResponse` | An entity that is returned from an instance of a `FacebookHttpClientInterface` that represents a raw HTTP response from the Graph API. |
92-
| [`Facebook\PersistentData\PersistentDataInterface`](reference/PersistentDataInterface.md) | An interface to code your own persistent data storage implementation. |
93-
| [`Facebook\Url\UrlDetectionInterface`](reference/UrlDetectionInterface.md) | An interface to code your own URL detection logic. |

0 commit comments

Comments
 (0)