Skip to content
Snippets Groups Projects
Unverified Commit 90b3e4ec authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

PSR2

parent efd1b4f9
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace SimpleSAML\Module\authfacebook\Auth\Source; namespace SimpleSAML\Module\authfacebook\Auth\Source;
use SimpleSAML\Module;
/** /**
* Authenticate using Facebook Platform. * Authenticate using Facebook Platform.
* *
...@@ -62,14 +64,15 @@ class Facebook extends \SimpleSAML\Auth\Source ...@@ -62,14 +64,15 @@ class Facebook extends \SimpleSAML\Auth\Source
* @param array $info Information about this authentication source. * @param array $info Information about this authentication source.
* @param array $config Configuration. * @param array $config Configuration.
*/ */
public function __construct($info, $config) { public function __construct($info, $config)
{
assert(is_array($info)); assert(is_array($info));
assert(is_array($config)); assert(is_array($config));
// Call the parent constructor first, as required by the interface // Call the parent constructor first, as required by the interface
parent::__construct($info, $config); parent::__construct($info, $config);
$cfgParse = \SimpleSAML\Configuration::loadFromArray($config, 'authsources[' . var_export($this->authId, TRUE) . ']'); $cfgParse = \SimpleSAML\Configuration::loadFromArray($config, 'authsources['.var_export($this->authId, true).']');
$this->api_key = $cfgParse->getString('api_key'); $this->api_key = $cfgParse->getString('api_key');
$this->secret = $cfgParse->getString('secret'); $this->secret = $cfgParse->getString('secret');
...@@ -83,17 +86,18 @@ class Facebook extends \SimpleSAML\Auth\Source ...@@ -83,17 +86,18 @@ class Facebook extends \SimpleSAML\Auth\Source
* *
* @param array &$state Information about the current authentication. * @param array &$state Information about the current authentication.
*/ */
public function authenticate(&$state) { public function authenticate(&$state)
{
assert(is_array($state)); assert(is_array($state));
// We are going to need the authId in order to retrieve this authentication source later // We are going to need the authId in order to retrieve this authentication source later
$state[self::AUTHID] = $this->authId; $state[self::AUTHID] = $this->authId;
\SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT); \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
$facebook = new \SimpleSAML\Module\authfacebook\Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state); $facebook = new Module\authfacebook\Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state);
$facebook->destroySession(); $facebook->destroySession();
$linkback = \SimpleSAML\Module::getModuleURL('authfacebook/linkback.php'); $linkback = Module::getModuleURL('authfacebook/linkback.php');
$url = $facebook->getLoginUrl(array('redirect_uri' => $linkback, 'scope' => $this->req_perms)); $url = $facebook->getLoginUrl(array('redirect_uri' => $linkback, 'scope' => $this->req_perms));
\SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT); \SimpleSAML\Auth\State::saveState($state, self::STAGE_INIT);
...@@ -101,15 +105,16 @@ class Facebook extends \SimpleSAML\Auth\Source ...@@ -101,15 +105,16 @@ class Facebook extends \SimpleSAML\Auth\Source
} }
public function finalStep(&$state) { public function finalStep(&$state)
{
assert(is_array($state)); assert(is_array($state));
$facebook = new \SimpleSAML\Module\authfacebook\Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state); $facebook = new Module\authfacebook\Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state);
$uid = $facebook->getUser(); $uid = $facebook->getUser();
if (isset($uid) && $uid) { if (isset($uid) && $uid) {
try { try {
$info = $facebook->api("/" . $uid . ($this->user_fields ? "?fields=" . $this->user_fields : "")); $info = $facebook->api("/".$uid.($this->user_fields ? "?fields=".$this->user_fields : ""));
} catch (\FacebookApiException $e) { } catch (\FacebookApiException $e) {
throw new \SimpleSAML\Error\AuthSource($this->authId, 'Error getting user profile.', $e); throw new \SimpleSAML\Error\AuthSource($this->authId, 'Error getting user profile.', $e);
} }
...@@ -120,26 +125,25 @@ class Facebook extends \SimpleSAML\Auth\Source ...@@ -120,26 +125,25 @@ class Facebook extends \SimpleSAML\Auth\Source
} }
$attributes = array(); $attributes = array();
foreach($info AS $key => $value) { foreach ($info as $key => $value) {
if (is_string($value) && !empty($value)) { if (is_string($value) && !empty($value)) {
$attributes['facebook.' . $key] = array((string)$value); $attributes['facebook.'.$key] = array((string)$value);
} }
} }
if (array_key_exists('third_party_id', $info)) { if (array_key_exists('third_party_id', $info)) {
$attributes['facebook_user'] = array($info['third_party_id'] . '@facebook.com'); $attributes['facebook_user'] = array($info['third_party_id'].'@facebook.com');
} else { } else {
$attributes['facebook_user'] = array($uid . '@facebook.com'); $attributes['facebook_user'] = array($uid.'@facebook.com');
} }
$attributes['facebook_targetedID'] = array('http://facebook.com!' . $uid); $attributes['facebook_targetedID'] = array('http://facebook.com!' . $uid);
$attributes['facebook_cn'] = array($info['name']); $attributes['facebook_cn'] = array($info['name']);
\SimpleSAML\Logger::debug('Facebook Returned Attributes: '. implode(", ", array_keys($attributes))); \SimpleSAML\Logger::debug('Facebook Returned Attributes: '.implode(", ", array_keys($attributes)));
$state['Attributes'] = $attributes; $state['Attributes'] = $attributes;
$facebook->destroySession(); $facebook->destroySession();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment