CIS: CIWorker works; now we need communication via web services
[living-lab-site.git] / application / libraries / Openid.php
index 7fd12fd..8cb1f90 100644 (file)
@@ -14,10 +14,13 @@ if (!defined('BASEPATH'))
 class Openid {
 
        var $storePath = 'tmp';
+       
        var $sreg_enable = FALSE;
        var $sreg_required = NULL;
        var $sreg_optional = NULL;
        var $sreg_policy = NULL;
+       var $ax_enable  = FALSE;
+       var $ax_attributes = NULL;
        var $pape_enable = FALSE;
        var $pape_policy_uris = NULL;
        var $ext_args = NULL;
@@ -45,6 +48,7 @@ class Openid {
                require_once "Auth/OpenID/SReg.php";
                require_once "Auth/OpenID/AX.php";
                require_once "Auth/OpenID/PAPE.php";
+               require_once "Auth/extensions.php";
        }
 
        function set_sreg($enable, $required = NULL, $optional = NULL, $policy = NULL)
@@ -54,6 +58,12 @@ class Openid {
                $this->sreg_optional = $optional;
                $this->sreg_policy = $policy;
        }
+       
+       function set_ax($enable, $ax_attributes = NULL)
+       {
+               $this->ax_enable = $enable;
+               $this->ax_attributes = $ax_attributes;
+       }
 
        function set_pape($enable, $policy_uris = NULL)
        {
@@ -115,32 +125,21 @@ class Openid {
                        }
                }
                
-               
-               
-               // *** TODO ***
-               
-               // Create attribute request object
-               // See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters
-               // Usage: make($type_uri, $count=1, $required=false, $alias=null)
-               $attribute[] = Auth_OpenID_AX_AttrInfo::make(
-                               'http://axschema.org/contact/email', 1, TRUE);
-               $attribute[] = Auth_OpenID_AX_AttrInfo::make(
-                               'http://axschema.org/namePerson/first', 1, TRUE);
-               $attribute[] = Auth_OpenID_AX_AttrInfo::make(
-                               'http://axschema.org/namePerson/last', 1, TRUE);
-
-               // Create AX fetch request
-               $ax = new Auth_OpenID_AX_FetchRequest;
-
-               // Add attributes to AX fetch request
-               foreach($attribute as $attr){
-                       $ax->add($attr);
+               if ($this->ax_enable)
+               {
+                       $ax_request = new Auth_OpenID_AX_FetchRequest();
+                       
+                       if ($ax_request)
+                       {
+                               foreach ($this->ax_attributes as $attr)
+                                       $ax_request->add($attr);
+                               $authRequest->addExtension($ax_request);
+                       }
+                       else
+                       {
+                               $this->_set_message(TRUE, 'openid_ax_failed');
+                       }
                }
-
-               // Add AX fetch request to authentication request
-               $authRequest->addExtension($ax);
-               
-               
                
                if ($this->pape_enable)
                {
@@ -227,7 +226,8 @@ class Openid {
                }
 
                $store = new Auth_OpenID_FileStore($this->storePath);
-               $consumer = new Auth_OpenID_Consumer($store);
+               $consumer = new Auth_OpenID_Consumer($store,
+                               new Auth_Yadis_CISession());
 
                return $consumer;
        }