You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/examples/access_token_from_canvas.md
+13-18
Original file line number
Diff line number
Diff line change
@@ -4,37 +4,32 @@ This example covers obtaining an access token and signed request from within the
4
4
5
5
## Example
6
6
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.
Copy file name to clipboardExpand all lines: docs/getting_started.md
+3-101
Original file line number
Diff line number
Diff line change
@@ -50,113 +50,15 @@ The `Facebook\Facebook` service ties all the components of the SDK for PHP toget
50
50
51
51
The SDK can be used to support logging a Facebook user into your site using Facebook Login which is based on OAuth 2.0.
52
52
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.
echo '<ahref="' . $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.
// 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.
101
54
102
55
### Obtaining an access token from a Facebook Canvas context
103
56
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.
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
132
58
133
59
### Obtaining an access token from the SDK for JavaScript
134
60
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.
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.
Copy file name to clipboardExpand all lines: docs/reference.md
-6
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,6 @@ These classes facilitate authenticating a Facebook user with OAuth 2.0.
17
17
18
18
| Class name | Description |
19
19
| ------------- | ------------- |
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. |
21
20
|[`Facebook\Authentication\AccessToken`](reference/AccessToken.md)| An entity that represents an access token. |
22
21
|`Facebook\Authentication\AccessTokenMetadata`| An entity that represents metadata from an access token. |
23
22
|`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.
41
40
42
41
| Class name | Description |
43
42
| ------------- | ------------- |
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. |
47
43
|[`Facebook\SignedRequest`](reference/SignedRequest.md)| An entity that represents a signed request. |
48
44
49
45
# Core Exceptions
@@ -89,5 +85,3 @@ You can overwrite certain functionality of the SDK by coding to an interface and
89
85
| ------------- | ------------- |
90
86
|`Facebook\HttpClients\ FacebookHttpClientInterface`| An interface to code your own HTTP client implementation. |
91
87
|`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