ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
|
Provides access to the Facebook Platform. More...
Public Member Functions | |
__construct ($config) | |
Initialize a Facebook Application. More... | |
setAppId ($appId) | |
Set the Application ID. More... | |
getAppId () | |
Get the Application ID. More... | |
setApiSecret ($apiSecret) | |
Set the App Secret. More... | |
setAppSecret ($appSecret) | |
Set the App Secret. More... | |
getApiSecret () | |
Get the App Secret. More... | |
getAppSecret () | |
Get the App Secret. More... | |
setFileUploadSupport ($fileUploadSupport) | |
Set the file upload support status. More... | |
getFileUploadSupport () | |
Get the file upload support status. More... | |
useFileUploadSupport () | |
DEPRECATED! Please use getFileUploadSupport instead. More... | |
setAccessToken ($access_token) | |
Sets the access token for api calls. More... | |
setExtendedAccessToken () | |
Extend an access token, while removing the short-lived token that might have been generated via client-side flow. More... | |
getAccessToken () | |
Determines the access token that should be used for API calls. More... | |
getSignedRequest () | |
Retrieve the signed request, either from a request parameter or, if not present, from a cookie. More... | |
getUser () | |
Get the UID of the connected user, or 0 if the Facebook user is not connected. More... | |
getLoginUrl ($params=array()) | |
Get a Login URL for use with redirects. More... | |
getLogoutUrl ($params=array()) | |
Get a Logout URL suitable for use with redirects. More... | |
getLoginStatusUrl ($params=array()) | |
Get a login status URL to fetch the status from Facebook. More... | |
api () | |
Make an API call. More... | |
destroySession () | |
Destroy the current session. More... | |
Data Fields | |
const | VERSION = '3.2.2' |
Version. More... | |
const | SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256' |
Signed Request Algorithm. More... | |
Static Public Attributes | |
static | $CURL_OPTS |
Default options for curl. More... | |
static | $DOMAIN_MAP |
Maps aliases to Facebook domains. More... | |
Protected Member Functions | |
getUserAccessToken () | |
Determines and returns the user access token, first using the signed request if present, and then falling back on the authorization code if present. More... | |
getUserFromAvailableData () | |
Determines the connected user by first examining any signed requests, then considering an authorization code, and then falling back to any persistent store storing the user. More... | |
getSignedRequestCookieName () | |
Constructs and returns the name of the cookie that potentially houses the signed request for the app user. More... | |
getMetadataCookieName () | |
Constructs and returns the name of the coookie that potentially contain metadata. More... | |
getCode () | |
Get the authorization code from the query parameters, if it exists, and otherwise return false to signal no authorization code was discoverable. More... | |
getUserFromAccessToken () | |
Retrieves the UID with the understanding that $this->accessToken has already been set and is seemingly legitimate. More... | |
getApplicationAccessToken () | |
Returns the access token that should be used for logged out users when no authorization code is available. More... | |
establishCSRFTokenState () | |
Lays down a CSRF state token for this process. More... | |
getAccessTokenFromCode ($code, $redirect_uri=null) | |
Retrieves an access token for the given authorization code (previously generated from www.facebook.com on behalf of a specific user). More... | |
_restserver ($params) | |
Invoke the old restserver.php endpoint. More... | |
isVideoPost ($path, $method='GET') | |
Return true if this is video post. More... | |
_graph ($path, $method='GET', $params=array()) | |
Invoke the Graph API. More... | |
_oauthRequest ($url, $params) | |
Make a OAuth Request. More... | |
makeRequest ($url, $params, $ch=null) | |
Makes an HTTP request. More... | |
parseSignedRequest ($signed_request) | |
Parses a signed_request and validates the signature. More... | |
makeSignedRequest ($data) | |
Makes a signed_request blob using the given data. More... | |
getApiUrl ($method) | |
Build the URL for api given parameters. More... | |
getUrl ($name, $path='', $params=array()) | |
Build the URL for given domain alias, path and parameters. More... | |
getHttpHost () | |
getHttpProtocol () | |
getBaseDomain () | |
Get the base domain used for the cookie. More... | |
getCurrentUrl () | |
Returns the Current URL, stripping it of known FB parameters that should not persist. More... | |
throwAPIException ($result) | |
Analyzes the supplied result to see if it was thrown because the access token is no longer valid. More... | |
getMetadataCookie () | |
Parses the metadata cookie that our Javascript API set. More... | |
setPersistentData ($key, $value) | |
Each of the following four methods should be overridden in a concrete subclass, as they are in the provided Facebook class. More... | |
getPersistentData ($key, $default=false) | |
Get the data for $key, persisted by BaseFacebook::setPersistentData() More... | |
clearPersistentData ($key) | |
Clear the data with $key from the persistent storage. More... | |
clearAllPersistentData () | |
Clear all data from the persistent storage. More... | |
Static Protected Member Functions | |
static | errorLog ($msg) |
Prints to the error log if you aren't in command line mode. More... | |
static | base64UrlDecode ($input) |
Base64 encoding that doesn't need to be urlencode()ed. More... | |
static | base64UrlEncode ($input) |
Base64 encoding that doesn't need to be urlencode()ed. More... | |
static | isAllowedDomain ($big, $small) |
static | endsWith ($big, $small) |
Protected Attributes | |
$appId | |
$appSecret | |
$user | |
$signedRequest | |
The data from the signed_request token. More... | |
$state | |
A CSRF state variable to assist in the defense against CSRF attacks. More... | |
$accessToken = null | |
$fileUploadSupport = false | |
$trustForwarded = false | |
Provides access to the Facebook Platform.
This class provides a majority of the functionality needed, but the class is abstract because it is designed to be sub-classed. The subclass must implement the four abstract methods listed at the bottom of the file.
Definition at line 118 of file base_facebook.php.
BaseFacebook::__construct | ( | $config | ) |
Initialize a Facebook Application.
The configuration:
array | $config | The application configuration |
Definition at line 215 of file base_facebook.php.
References $config, $state, getPersistentData(), setAppId(), setAppSecret(), and setFileUploadSupport().
|
protected |
Invoke the Graph API.
string | $path | The path (required) |
string | $method | The http method (default 'GET') |
array | $params | The query/post data |
FacebookApiException |
Definition at line 852 of file base_facebook.php.
References PHPMailer\PHPMailer\$params, $path, $result, _oauthRequest(), getUrl(), isVideoPost(), and throwAPIException().
|
protected |
Make a OAuth Request.
string | $url | The path (required) |
array | $params | The query/post data |
FacebookApiException |
Definition at line 889 of file base_facebook.php.
References $key, PHPMailer\PHPMailer\$params, $url, getAccessToken(), and makeRequest().
Referenced by _graph(), _restserver(), getAccessTokenFromCode(), and setExtendedAccessToken().
|
protected |
Invoke the old restserver.php endpoint.
array | $params | Method call object |
FacebookApiException |
Definition at line 801 of file base_facebook.php.
References PHPMailer\PHPMailer\$params, $result, _oauthRequest(), destroySession(), getApiUrl(), getAppId(), and throwAPIException().
Referenced by api().
BaseFacebook::api | ( | ) |
Make an API call.
Definition at line 639 of file base_facebook.php.
References _restserver().
Referenced by getUserFromAccessToken().
|
staticprotected |
Base64 encoding that doesn't need to be urlencode()ed.
Exactly the same as base64_encode except it uses
string | $input | base64UrlEncoded string |
Definition at line 1253 of file base_facebook.php.
References $input.
Referenced by parseSignedRequest().
|
staticprotected |
Base64 encoding that doesn't need to be urlencode()ed.
Exactly the same as base64_encode except it uses
string | $input | string |
Definition at line 1266 of file base_facebook.php.
References $input.
Referenced by makeSignedRequest().
|
abstractprotected |
Clear all data from the persistent storage.
Reimplemented in sspmod_authfacebook_Facebook.
Referenced by destroySession(), getUserAccessToken(), and getUserFromAvailableData().
|
abstractprotected |
Clear the data with $key from the persistent storage.
string | $key |
Reimplemented in sspmod_authfacebook_Facebook.
Referenced by getCode().
BaseFacebook::destroySession | ( | ) |
Destroy the current session.
Definition at line 1275 of file base_facebook.php.
References $_COOKIE, clearAllPersistentData(), errorLog(), getBaseDomain(), getSignedRequestCookieName(), and user().
Referenced by _restserver(), setExtendedAccessToken(), and throwAPIException().
|
staticprotected |
Definition at line 1339 of file base_facebook.php.
Referenced by isAllowedDomain().
|
staticprotected |
Prints to the error log if you aren't in command line mode.
string | $msg | Log message |
Definition at line 1234 of file base_facebook.php.
References Monolog\Handler\error_log().
Referenced by destroySession(), getAccessTokenFromCode(), getCode(), makeRequest(), and parseSignedRequest().
|
protected |
Lays down a CSRF state token for this process.
Reimplemented in sspmod_authfacebook_Facebook.
Definition at line 734 of file base_facebook.php.
References setPersistentData().
Referenced by getLoginUrl().
BaseFacebook::getAccessToken | ( | ) |
Determines the access token that should be used for API calls.
The first time this is called, $this->accessToken is set equal to either a valid user access token, or it's set to the application access token if a valid user access token wasn't available. Subsequent calls return whatever the first call returned.
Definition at line 388 of file base_facebook.php.
References $accessToken, getApplicationAccessToken(), getUserAccessToken(), and setAccessToken().
Referenced by _oauthRequest(), getUserFromAvailableData(), and setExtendedAccessToken().
|
protected |
Retrieves an access token for the given authorization code (previously generated from www.facebook.com on behalf of a specific user).
The authorization code is sent to graph.facebook.com and a legitimate access token is generated provided the access token and the user for which it was generated all match, and the user is either logged in to Facebook or has granted an offline access permission.
string | $code | An authorization code. |
Definition at line 753 of file base_facebook.php.
References $code, PHPMailer\PHPMailer\$params, _oauthRequest(), errorLog(), getAppId(), getAppSecret(), getCurrentUrl(), and getUrl().
Referenced by getUserAccessToken().
BaseFacebook::getApiSecret | ( | ) |
Get the App Secret.
Definition at line 279 of file base_facebook.php.
References getAppSecret().
|
protected |
Build the URL for api given parameters.
$method | String the method name. |
Definition at line 1039 of file base_facebook.php.
References $name, and getUrl().
Referenced by _restserver().
BaseFacebook::getAppId | ( | ) |
Get the Application ID.
Definition at line 246 of file base_facebook.php.
References $appId.
Referenced by _restserver(), sspmod_authfacebook_Facebook\constructSessionVariableName(), getAccessTokenFromCode(), getLoginStatusUrl(), getLoginUrl(), sspmod_authfacebook_Facebook\getSharedSessionCookieName(), and setExtendedAccessToken().
|
protected |
Returns the access token that should be used for logged out users when no authorization code is available.
Definition at line 725 of file base_facebook.php.
References $appSecret.
Referenced by getAccessToken(), and getUserFromAvailableData().
BaseFacebook::getAppSecret | ( | ) |
Get the App Secret.
Definition at line 288 of file base_facebook.php.
References $appSecret.
Referenced by getAccessTokenFromCode(), getApiSecret(), makeSignedRequest(), parseSignedRequest(), and setExtendedAccessToken().
|
protected |
Get the base domain used for the cookie.
Definition at line 1164 of file base_facebook.php.
References $metadata, getHttpHost(), and getMetadataCookie().
Referenced by sspmod_authfacebook_Facebook\deleteSharedSessionCookie(), destroySession(), and sspmod_authfacebook_Facebook\initSharedSession().
|
protected |
Get the authorization code from the query parameters, if it exists, and otherwise return false to signal no authorization code was discoverable.
Definition at line 680 of file base_facebook.php.
References clearPersistentData(), and errorLog().
Referenced by getUserAccessToken().
|
protected |
Returns the Current URL, stripping it of known FB parameters that should not persist.
Definition at line 1181 of file base_facebook.php.
References GuzzleHttp\Psr7\$protocol, getHttpHost(), and getHttpProtocol().
Referenced by getAccessTokenFromCode(), getLoginStatusUrl(), getLoginUrl(), and getLogoutUrl().
BaseFacebook::getFileUploadSupport | ( | ) |
Get the file upload support status.
Definition at line 308 of file base_facebook.php.
References $fileUploadSupport.
Referenced by makeRequest(), and useFileUploadSupport().
|
protected |
Definition at line 1134 of file base_facebook.php.
References $_SERVER.
Referenced by getBaseDomain(), getCurrentUrl(), and sspmod_authfacebook_Facebook\initSharedSession().
|
protected |
Definition at line 1141 of file base_facebook.php.
References $_SERVER.
Referenced by getCurrentUrl().
BaseFacebook::getLoginStatusUrl | ( | $params = array() | ) |
Get a login status URL to fetch the status from Facebook.
The parameters:
array | $params | Provide custom parameters |
Definition at line 620 of file base_facebook.php.
References PHPMailer\PHPMailer\$params, getAppId(), getCurrentUrl(), and getUrl().
BaseFacebook::getLoginUrl | ( | $params = array() | ) |
Get a Login URL for use with redirects.
By default, full page redirect is assumed. If you are using the generated URL with a window.open() call in JavaScript, you can pass in display=popup as part of the $params.
The parameters:
array | $params | Provide custom parameters |
Definition at line 569 of file base_facebook.php.
References PHPMailer\PHPMailer\$params, establishCSRFTokenState(), getAppId(), getCurrentUrl(), and getUrl().
BaseFacebook::getLogoutUrl | ( | $params = array() | ) |
Get a Logout URL suitable for use with redirects.
The parameters:
array | $params | Provide custom parameters |
Definition at line 598 of file base_facebook.php.
References PHPMailer\PHPMailer\$params, getCurrentUrl(), getUrl(), and getUserAccessToken().
|
protected |
Parses the metadata cookie that our Javascript API set.
Definition at line 1306 of file base_facebook.php.
References $_COOKIE, $metadata, and getMetadataCookieName().
Referenced by getBaseDomain().
|
protected |
Constructs and returns the name of the coookie that potentially contain metadata.
The cookie is not set by the BaseFacebook class, but it may be set by the JavaScript SDK.
Definition at line 668 of file base_facebook.php.
Referenced by getMetadataCookie().
|
abstractprotected |
Get the data for $key, persisted by BaseFacebook::setPersistentData()
string | $key | The key of the data to retrieve |
boolean | $default | The default value to return if $key is not found |
Reimplemented in sspmod_authfacebook_Facebook.
Referenced by __construct(), getUserAccessToken(), and getUserFromAvailableData().
BaseFacebook::getSignedRequest | ( | ) |
Retrieve the signed request, either from a request parameter or, if not present, from a cookie.
Definition at line 479 of file base_facebook.php.
References $_COOKIE, $signedRequest, getSignedRequestCookieName(), and parseSignedRequest().
Referenced by getUserAccessToken(), and getUserFromAvailableData().
|
protected |
Constructs and returns the name of the cookie that potentially houses the signed request for the app user.
The cookie is not set by the BaseFacebook class, but it may be set by the JavaScript SDK.
Definition at line 657 of file base_facebook.php.
Referenced by destroySession(), and getSignedRequest().
|
protected |
Build the URL for given domain alias, path and parameters.
$name | string The name of the domain |
$path | string Optional path (without a leading slash) |
$params | array Optional query parameters |
Definition at line 1119 of file base_facebook.php.
References $name, PHPMailer\PHPMailer\$params, $path, and $url.
Referenced by _graph(), getAccessTokenFromCode(), getApiUrl(), getLoginStatusUrl(), getLoginUrl(), getLogoutUrl(), and setExtendedAccessToken().
BaseFacebook::getUser | ( | ) |
Get the UID of the connected user, or 0 if the Facebook user is not connected.
Definition at line 498 of file base_facebook.php.
References $user, getUserFromAvailableData(), and user().
|
protected |
Determines and returns the user access token, first using the signed request if present, and then falling back on the authorization code if present.
The intent is to return a valid user access token, or false if one is determined to not be available.
Definition at line 416 of file base_facebook.php.
References $code, clearAllPersistentData(), getAccessTokenFromCode(), getCode(), getPersistentData(), getSignedRequest(), and setPersistentData().
Referenced by getAccessToken(), and getLogoutUrl().
|
protected |
Retrieves the UID with the understanding that $this->accessToken has already been set and is seemingly legitimate.
It relies on Facebook's Graph API to retrieve user information and then extract the user ID.
Definition at line 709 of file base_facebook.php.
References api().
Referenced by getUserFromAvailableData().
|
protected |
Determines the connected user by first examining any signed requests, then considering an authorization code, and then falling back to any persistent store storing the user.
Definition at line 515 of file base_facebook.php.
References $default, $user, clearAllPersistentData(), getAccessToken(), getApplicationAccessToken(), getPersistentData(), getSignedRequest(), getUserFromAccessToken(), and setPersistentData().
Referenced by getUser().
|
staticprotected |
Definition at line 1332 of file base_facebook.php.
References endsWith().
|
protected |
Return true if this is video post.
string | $path | The path |
string | $method | The http method (default 'GET') |
Definition at line 835 of file base_facebook.php.
References $path.
Referenced by _graph().
|
protected |
Makes an HTTP request.
This method can be overridden by subclasses if developers want to do fancier things or use something other than curl to make the request.
string | $url | The URL to make the request to |
array | $params | The parameters to use for the POST body |
CurlHandler | $ch | Initialized curl handle |
Definition at line 915 of file base_facebook.php.
References $CURL_OPTS, PHPMailer\PHPMailer\$params, $result, $url, errorLog(), and getFileUploadSupport().
Referenced by _oauthRequest().
|
protected |
Makes a signed_request blob using the given data.
array | The data array. |
Definition at line 1019 of file base_facebook.php.
References $data, base64UrlEncode(), getAppSecret(), and SIGNED_REQUEST_ALGORITHM.
Referenced by sspmod_authfacebook_Facebook\initSharedSession().
|
protected |
Parses a signed_request and validates the signature.
string | $signed_request | A signed token |
Definition at line 989 of file base_facebook.php.
References $data, base64UrlDecode(), errorLog(), and getAppSecret().
Referenced by getSignedRequest(), and sspmod_authfacebook_Facebook\initSharedSession().
BaseFacebook::setAccessToken | ( | $access_token | ) |
Sets the access token for api calls.
Use this if you get your access token by other means and just want the SDK to use it.
string | $access_token | an access token. |
Definition at line 331 of file base_facebook.php.
Referenced by getAccessToken().
BaseFacebook::setApiSecret | ( | $apiSecret | ) |
Set the App Secret.
string | $apiSecret | The App Secret |
Definition at line 257 of file base_facebook.php.
References setAppSecret().
BaseFacebook::setAppId | ( | $appId | ) |
Set the Application ID.
string | $appId | The Application ID |
Definition at line 236 of file base_facebook.php.
References $appId.
Referenced by __construct().
BaseFacebook::setAppSecret | ( | $appSecret | ) |
Set the App Secret.
string | $appSecret | The App Secret |
Definition at line 268 of file base_facebook.php.
References $appSecret.
Referenced by __construct(), and setApiSecret().
BaseFacebook::setExtendedAccessToken | ( | ) |
Extend an access token, while removing the short-lived token that might have been generated via client-side flow.
Thanks to http://bit.ly/b0Pt0H for the workaround.
Definition at line 341 of file base_facebook.php.
References PHPMailer\PHPMailer\$params, _oauthRequest(), destroySession(), getAccessToken(), getAppId(), getAppSecret(), getUrl(), and setPersistentData().
BaseFacebook::setFileUploadSupport | ( | $fileUploadSupport | ) |
Set the file upload support status.
boolean | $fileUploadSupport | The file upload support status. |
Definition at line 298 of file base_facebook.php.
References $fileUploadSupport.
Referenced by __construct().
|
abstractprotected |
Each of the following four methods should be overridden in a concrete subclass, as they are in the provided Facebook class.
The Facebook class uses PHP sessions to provide a primitive persistent store, but another subclass–one that you implement– might use a database, memcache, or an in-memory cache.
string | $key | |
array | $value |
Reimplemented in sspmod_authfacebook_Facebook.
Referenced by establishCSRFTokenState(), getUserAccessToken(), getUserFromAvailableData(), and setExtendedAccessToken().
|
protected |
Analyzes the supplied result to see if it was thrown because the access token is no longer valid.
If that is the case, then we destroy the session.
$result | array A record storing the error message returned by a failed API call. |
Definition at line 1206 of file base_facebook.php.
References $message, $result, and destroySession().
Referenced by _graph(), and _restserver().
BaseFacebook::useFileUploadSupport | ( | ) |
DEPRECATED! Please use getFileUploadSupport instead.
Get the file upload support status.
Definition at line 319 of file base_facebook.php.
References getFileUploadSupport().
|
protected |
Definition at line 189 of file base_facebook.php.
Referenced by getAccessToken().
|
protected |
Definition at line 157 of file base_facebook.php.
Referenced by getAppId(), and setAppId().
|
protected |
Definition at line 164 of file base_facebook.php.
Referenced by getApplicationAccessToken(), getAppSecret(), and setAppSecret().
|
static |
Default options for curl.
Definition at line 133 of file base_facebook.php.
Referenced by makeRequest().
|
static |
Maps aliases to Facebook domains.
Definition at line 143 of file base_facebook.php.
|
protected |
Definition at line 196 of file base_facebook.php.
Referenced by getFileUploadSupport(), and setFileUploadSupport().
|
protected |
The data from the signed_request token.
Definition at line 176 of file base_facebook.php.
Referenced by getSignedRequest().
|
protected |
A CSRF state variable to assist in the defense against CSRF attacks.
Definition at line 181 of file base_facebook.php.
Referenced by __construct().
|
protected |
Definition at line 203 of file base_facebook.php.
|
protected |
Definition at line 171 of file base_facebook.php.
Referenced by getUser(), and getUserFromAvailableData().
const BaseFacebook::SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256' |
Signed Request Algorithm.
Definition at line 128 of file base_facebook.php.
Referenced by makeSignedRequest().
const BaseFacebook::VERSION = '3.2.2' |
Version.
Definition at line 123 of file base_facebook.php.