From f15764b43d4b943267fecd78567b7a6e46e3492c Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Tue, 5 May 2009 05:56:32 +0000 Subject: [PATCH] openid: Make requested attributes configurable. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1488 44740490-163a-0410-bde0-09ae8108e29a --- config-templates/authsources.php | 2 ++ .../openid/lib/Auth/Source/OpenIDConsumer.php | 36 +++++++++++++++++++ modules/openid/www/consumer.php | 6 ++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/config-templates/authsources.php b/config-templates/authsources.php index 1370ffc36..a8187f637 100644 --- a/config-templates/authsources.php +++ b/config-templates/authsources.php @@ -53,6 +53,8 @@ $config = array( 'openid' => array( 'openid:OpenIDConsumer', + 'attributes.required' => array('nickname'), + 'attributes.optional' => array('fullname', 'email',), ), 'feide' => array( diff --git a/modules/openid/lib/Auth/Source/OpenIDConsumer.php b/modules/openid/lib/Auth/Source/OpenIDConsumer.php index 0d42f83e0..1d0c4de7b 100644 --- a/modules/openid/lib/Auth/Source/OpenIDConsumer.php +++ b/modules/openid/lib/Auth/Source/OpenIDConsumer.php @@ -9,6 +9,17 @@ */ class sspmod_openid_Auth_Source_OpenIDConsumer extends SimpleSAML_Auth_Source { + /** + * List of optional attributes. + */ + private $optionalAttributes; + + + /** + * List of required attributes. + */ + private $requiredAttributes; + /** * Constructor for this authentication source. @@ -21,6 +32,11 @@ class sspmod_openid_Auth_Source_OpenIDConsumer extends SimpleSAML_Auth_Source { /* Call the parent constructor first, as required by the interface. */ parent::__construct($info, $config); + $cfgParse = SimpleSAML_Configuration::loadFromArray($config, + 'Authentication source ' . var_export($this->authId, TRUE)); + + $this->optionalAttributes = $cfgParse->getArray('attributes.optional', array()); + $this->requiredAttributes = $cfgParse->getArray('attributes.required', array()); } @@ -40,6 +56,26 @@ class sspmod_openid_Auth_Source_OpenIDConsumer extends SimpleSAML_Auth_Source { SimpleSAML_Utilities::redirect($url, array('AuthState' => $id)); } + + /** + * Retrieve required attributes. + * + * @return array Required attributes. + */ + public function getRequiredAttributes() { + return $this->requiredAttributes; + } + + + /** + * Retrieve optional attributes. + * + * @return array Optional attributes. + */ + public function getOptionalAttributes() { + return $this->optionalAttributes; + } + } ?> \ No newline at end of file diff --git a/modules/openid/www/consumer.php b/modules/openid/www/consumer.php index f0ca314f9..a808841c6 100644 --- a/modules/openid/www/consumer.php +++ b/modules/openid/www/consumer.php @@ -88,6 +88,8 @@ function getTrustRoot() { } function run_try_auth() { + global $authSource; + $openid = getOpenIDURL(); $consumer = getConsumer(); @@ -100,8 +102,8 @@ function run_try_auth() { } $sreg_request = Auth_OpenID_SRegRequest::build( - array('nickname'), // Required - array('fullname', 'email')); // Optional + $authSource->getRequiredAttributes(), + $authSource->getOptionalAttributes()); if ($sreg_request) { $auth_request->addExtension($sreg_request); -- GitLab