JSession help needed to finish openID authentication plugin - Joomla! Forum - community, help and support


hi all

i've spent last couple of days working on openid authentication plugin joomla. i'm soooo close getting thing working stumped on 1 issue

before go explaining let me i'm hacking example code found here:
http://www.openidenabled.com/openid/libraries/php/

the flow of code plugin takes openid login url , builds array of data stores in session. example of

code: select all

   [_openid_consumer_last_token] => array
        (
            [identity_url] => http://pollen.myopenid.com/
            [server_url] => http://www.myopenid.com/server
            [type_uris] => array
                (
                    [0] => http://openid.net/signon/1.0
                    [1] => http://openid.net/sreg/1.0
                )

            [delegate] => http://pollen.myopenid.com/
            [canonicalid] =>
            [used_yadis] => 1
        )

    [_yadis_services__openid_consumer_] => a:6:{s:12:"starting_url";s:27:"http://pollen.myopenid.com/";s:9:"yadis_url";s:27:"http://pollen.myopenid.com/";s:8:"services";a:0:{}s:11:"session_key";s:33:"_yadis_services__openid_consumer_";s:8:"_current";o:27:"auth_openid_serviceendpoint":6:{s:12:"identity_url";s:27:"http://pollen.myopenid.com/";s:10:"server_url";s:30:"http://www.myopenid.com/server";s:9:"type_uris";a:2:{i:0;s:28:"http://openid.net/signon/1.0";i:1;s:26:"http://openid.net/sreg/1.0";}s:8:"delegate";s:27:"http://pollen.myopenid.com/";s:11:"canonicalid";n;s:10:"used_yadis";b:1;}s:5:"stale";b:1;}


it redirects open id server allowing sign in , validate want allow joomla site use openid login.

the sample php code uses own session handling, says can override passing in own session handling object. i've passed in jsession object code , session data stored.

however when returning openid server whole part of session no longer there, causing validation of openid fail.

here jsession object before being redirected openid server:

code: select all

array
(
    [session.counter] => 47
    [session.timer.start] => 1164469322
    [session.timer.last] => 1164473982
    [session.timer.now] => 1164474043
    [session.client.address] => 90.5.133.242
    [session.client.browser] => mozilla/5.0 (windows; u; windows nt 5.1; en-gb; rv:1.8.1) gecko/20061010 firefox/2.0
    [session.token] => token_ff15c842f9ae9a963d31c41fa510a89a
    [registry] => jregistry object
        (
            [_defaultnamespace] => session
            [_registry] => array
                (
                    [session] => array
                        (
                            [data] => stdclass object
                                (
                                )

                        )

                )

        )

    [_openid_consumer_last_token] => array
        (
            [identity_url] => http://pollen.myopenid.com/
            [server_url] => http://www.myopenid.com/server
            [type_uris] => array
                (
                    [0] => http://openid.net/signon/1.0
                    [1] => http://openid.net/sreg/1.0
                )

            [delegate] => http://pollen.myopenid.com/
            [canonicalid] =>
            [used_yadis] => 1
        )

    [_yadis_services__openid_consumer_] => a:6:{s:12:"starting_url";s:27:"http://pollen.myopenid.com/";s:9:"yadis_url";s:27:"http://pollen.myopenid.com/";s:8:"services";a:0:{}s:11:"session_key";s:33:"_yadis_services__openid_consumer_";s:8:"_current";o:27:"auth_openid_serviceendpoint":6:{s:12:"identity_url";s:27:"http://pollen.myopenid.com/";s:10:"server_url";s:30:"http://www.myopenid.com/server";s:9:"type_uris";a:2:{i:0;s:28:"http://openid.net/signon/1.0";i:1;s:26:"http://openid.net/sreg/1.0";}s:8:"delegate";s:27:"http://pollen.myopenid.com/";s:11:"canonicalid";n;s:10:"used_yadis";b:1;}s:5:"stale";b:1;}
)


and jsession object when return openid server:

code: select all

array
(
    [session.counter] => 45
    [session.timer.start] => 1164469330
    [session.timer.last] => 1164473984
    [session.timer.now] => 1164474862
    [session.client.address] => 90.5.133.242
    [session.client.browser] => mozilla/5.0 (windows; u; windows nt 5.1; en-gb; rv:1.8.1) gecko/20061010 firefox/2.0
    [session.token] => token_2844f67eb3a6e6c75be7c3641eff9f6b
    [registry] => jregistry object
        (
            [_defaultnamespace] => session
            [_registry] => array
                (
                    [session] => array
                        (
                            [data] => stdclass object
                                (
                                )

                        )

                )

        )

)



i've noticed when create jsession object looks this:

code: select all

jsession object
(
    [_state] => error
    [_expire] => 15
)


i've tracked error down jsession::validate code checking token, possible error created  here causing session reset itself, , if how can stop error occuring

below plugin code have far:

code: select all


jimport('joomla.application.plugin.helper');

/**
 * openid jauthenticate plugin
 *
 * @authorrob clayburn <rob@pollen-8.cco.uk>
 * @package joomla
 * @subpackage openid
 * @since 1.5
 */
class jauthenticateopenid extends jplugin {

   /**
    * constructor
    *
    * php4 compatability must not use __constructor constructor plugins
    * because func_get_args ( void ) returns copy of passed arguments not references.
    * causes problems cross-referencing necessary observer design pattern.
    *
    * @param object $subject object observe
    * @since 1.5
    */
   function jauthenticateopenid(& $subject) {
      parent::__construct($subject);
   }

   /**
    * method should handle authentication , report subject
    *
    * @access   public
    * @param   string   $username   username authentication
    * @param   string   $password   password authentication
    * @return   object   jauthenticateresponse
    * @since 1.5
    */
   function onauthenticate( $username, $password )
   {
      global $mainframe;

      // database connector
      $db = jfactory::getdbo();

      $openid = jrequest::getvar('username', '');
      //this seems bit of hack lets assume openids start http://
      // if username doesnt start skip rest of plugin
      if(strtolower(substr($openid,0, 7)) == 'http://'){
         // load plugin parameters
          $plugin =& jpluginhelper::getplugin('authentication', 'openid');
          $pluginparams = new jparameter( $plugin->params );
         $return = new jauthenticateresponse('openid');
         
         
         /**
          * require openid consumer code.
          */
         jimport('php-openid.auth.openid.consumer');
         /**
          * require "file store" module, we'll need store openid
          * information.
          */
         jimport('php-openid.auth.openid.filestore');
         /**
          * example store openid information.  you
          * should change path if want example store created
          * elsewhere.  after you're done playing example script,
          * you'll have remove directory manually.
          */
         $store_path = "/tmp/_php_consumer_test";
         
         if (!file_exists($store_path) &&
             !mkdir($store_path)) {
             print "could not create filestore directory '$store_path'. ".
                 " please check effective permissions.";
             exit(0);
         }
         
         $store = new auth_openid_filestore($store_path);
         /**
          * create consumer object using store object created earlier.
          */
         $session =& jfactory::getsession();
         $consumer = new auth_openid_consumer($store, $session);
         

         $config         =& jfactory::getconfig();
                            
           $process_url =  $config->getvalue('config.live_site') . ":" . $_server['server_port'] . "/index.php?option=com_openid&task=auth";
         
         $trust_root = sprintf("%s:%s%s",
                              $config->getvalue('config.live_site'),  $_server['server_port'],
                               dirname($_server['php_self']));


         // begin openid authentication process.
         $auth_request = $consumer->begin($openid);
         // handle failure status return values.
         if (!$auth_request) {
             $error = "authentication error.";
             include 'index.php';
             exit(0);
         }
         
         $auth_request->addextensionarg('sreg', 'optional', 'email');
         
         // redirect user openid server authentication.  store
         // token authentication can verify response.
         
         $redirect_url = $auth_request->redirecturl($trust_root, $process_url);

         global $mainframe;
         $mainframe->redirect( $redirect_url);                                
         return false;
      }
   }
}



any appreciated!

hello,

maybe haven't noticed, have create component, plugin, module openid called churchkey (it's in extensoin repositoty , in forge)

maybe improve it.
i haven't tested 2 weeks. maybe won't work latest trunk.





Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support