ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
sspmod_authfacebook_Auth_Source_Facebook Class Reference
+ Inheritance diagram for sspmod_authfacebook_Auth_Source_Facebook:
+ Collaboration diagram for sspmod_authfacebook_Auth_Source_Facebook:

Public Member Functions

 __construct ($info, $config)
 Constructor for this authentication source. More...
 
 authenticate (&$state)
 Log-in using Facebook platform. More...
 
 finalStep (&$state)
 
- Public Member Functions inherited from SimpleSAML_Auth_Source
 __construct ($info, &$config)
 Constructor for an authentication source. More...
 
 getAuthId ()
 Retrieve the ID of this authentication source. More...
 
 authenticate (&$state)
 Process a request. More...
 
 reauthenticate (array &$state)
 Reauthenticate an user. More...
 
 initLogin ($return, $errorURL=null, array $params=array())
 Start authentication. More...
 
 logout (&$state)
 Log out from this authentication source. More...
 

Data Fields

const STAGE_INIT = 'facebook:init'
 The string used to identify our states. More...
 
const AUTHID = 'facebook:AuthId'
 The key of the AuthId field in the state. More...
 

Private Attributes

 $api_key
 Facebook App ID or API Key. More...
 
 $secret
 Facebook App Secret. More...
 
 $req_perms
 Which additional data permissions to request from user. More...
 
 $user_fields
 A comma-separated list of user profile fields to request. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from SimpleSAML_Auth_Source
static getSourcesOfType ($type)
 Get sources of a specific type. More...
 
static completeAuth (&$state)
 Complete authentication. More...
 
static loginCompleted ($state)
 Called when a login operation has finished. More...
 
static completeLogout (&$state)
 Complete logout. More...
 
static getById ($authId, $type=null)
 Retrieve authentication source. More...
 
static logoutCallback ($state)
 Called when the authentication source receives an external logout request. More...
 
static getSources ()
 Retrieve list of authentication sources. More...
 
- Protected Member Functions inherited from SimpleSAML_Auth_Source
 addLogoutCallback ($assoc, $state)
 Add a logout callback association. More...
 
 callLogoutCallback ($assoc)
 Call a logout callback based on association. More...
 
- Static Protected Member Functions inherited from SimpleSAML_Auth_Source
static validateSource ($source, $id)
 Make sure that the first element of an auth source is its identifier. More...
 
- Protected Attributes inherited from SimpleSAML_Auth_Source
 $authId
 

Detailed Description

Definition at line 9 of file Facebook.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_authfacebook_Auth_Source_Facebook::__construct (   $info,
  $config 
)

Constructor for this authentication source.

Parameters
array$infoInformation about this authentication source.
array$configConfiguration.

Definition at line 63 of file Facebook.php.

References $config, $info, and SimpleSAML_Configuration\loadFromArray().

63  {
64  assert('is_array($info)');
65  assert('is_array($config)');
66 
67  // Call the parent constructor first, as required by the interface
68  parent::__construct($info, $config);
69 
70  $cfgParse = SimpleSAML_Configuration::loadFromArray($config, 'authsources[' . var_export($this->authId, TRUE) . ']');
71 
72  $this->api_key = $cfgParse->getString('api_key');
73  $this->secret = $cfgParse->getString('secret');
74  $this->req_perms = $cfgParse->getString('req_perms', NULL);
75  $this->user_fields = $cfgParse->getString('user_fields', NULL);
76  }
$info
Definition: index.php:5
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
+ Here is the call graph for this function:

Member Function Documentation

◆ authenticate()

sspmod_authfacebook_Auth_Source_Facebook::authenticate ( $state)

Log-in using Facebook platform.

Parameters
array&$stateInformation about the current authentication.

Definition at line 84 of file Facebook.php.

References SimpleSAML_Auth_Source\$authId, $state, $url, array, SimpleSAML\Module\getModuleURL(), SimpleSAML\Utils\HTTP\redirectTrustedURL(), and SimpleSAML_Auth_State\saveState().

84  {
85  assert('is_array($state)');
86 
87  // We are going to need the authId in order to retrieve this authentication source later
88  $state[self::AUTHID] = $this->authId;
89  SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
90 
91  $facebook = new sspmod_authfacebook_Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state);
92  $facebook->destroySession();
93 
94  $linkback = SimpleSAML\Module::getModuleURL('authfacebook/linkback.php');
95  $url = $facebook->getLoginUrl(array('redirect_uri' => $linkback, 'scope' => $this->req_perms));
96  SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
97 
99  }
Extends the BaseFacebook class with the intent of using PHP sessions to store user ids and access tok...
Definition: Facebook.php:9
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Create styles array
The data for the language used.
$url
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
+ Here is the call graph for this function:

◆ finalStep()

sspmod_authfacebook_Auth_Source_Facebook::finalStep ( $state)

Definition at line 102 of file Facebook.php.

References $attributes, $info, $key, $state, array, and SimpleSAML\Logger\debug().

102  {
103  assert('is_array($state)');
104 
105  $facebook = new sspmod_authfacebook_Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state);
106  $uid = $facebook->getUser();
107 
108  if (isset($uid) && $uid) {
109  try {
110  $info = $facebook->api("/" . $uid . ($this->user_fields ? "?fields=" . $this->user_fields : ""));
111  } catch (FacebookApiException $e) {
112  throw new SimpleSAML_Error_AuthSource($this->authId, 'Error getting user profile.', $e);
113  }
114  }
115 
116  if (!isset($info)) {
117  throw new SimpleSAML_Error_AuthSource($this->authId, 'Error getting user profile.');
118  }
119 
120  $attributes = array();
121  foreach($info AS $key => $value) {
122  if (is_string($value) && !empty($value)) {
123  $attributes['facebook.' . $key] = array((string)$value);
124  }
125  }
126 
127  if (array_key_exists('third_party_id', $info)) {
128  $attributes['facebook_user'] = array($info['third_party_id'] . '@facebook.com');
129  } else {
130  $attributes['facebook_user'] = array($uid . '@facebook.com');
131  }
132 
133  $attributes['facebook_targetedID'] = array('http://facebook.com!' . $uid);
134  $attributes['facebook_cn'] = array($info['name']);
135 
136  SimpleSAML\Logger::debug('Facebook Returned Attributes: '. implode(", ", array_keys($attributes)));
137 
138  $state['Attributes'] = $attributes;
139 
140  $facebook->destroySession();
141  }
Extends the BaseFacebook class with the intent of using PHP sessions to store user ids and access tok...
Definition: Facebook.php:9
static debug($string)
Definition: Logger.php:213
$attributes
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Create styles array
The data for the language used.
$info
Definition: index.php:5
$key
Definition: croninfo.php:18
Copyright 2011 Facebook, Inc.
+ Here is the call graph for this function:

Field Documentation

◆ $api_key

sspmod_authfacebook_Auth_Source_Facebook::$api_key
private

Facebook App ID or API Key.

Definition at line 27 of file Facebook.php.

◆ $req_perms

sspmod_authfacebook_Auth_Source_Facebook::$req_perms
private

Which additional data permissions to request from user.

Definition at line 39 of file Facebook.php.

◆ $secret

sspmod_authfacebook_Auth_Source_Facebook::$secret
private

Facebook App Secret.

Definition at line 33 of file Facebook.php.

◆ $user_fields

sspmod_authfacebook_Auth_Source_Facebook::$user_fields
private

A comma-separated list of user profile fields to request.

Note that some user fields require appropriate permissions. For example, to retrieve the user's primary email address, "email" must be specified in both the req_perms and the user_fields parameter.

When empty, only the app-specific user id and name will be returned.

See the Graph API specification for all available user fields: https://developers.facebook.com/docs/graph-api/reference/v2.6/user

Definition at line 54 of file Facebook.php.

◆ AUTHID

const sspmod_authfacebook_Auth_Source_Facebook::AUTHID = 'facebook:AuthId'

The key of the AuthId field in the state.

Definition at line 21 of file Facebook.php.

◆ STAGE_INIT

const sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT = 'facebook:init'

The string used to identify our states.

Definition at line 15 of file Facebook.php.


The documentation for this class was generated from the following file: