oxopenid.php

Go to the documentation of this file.
00001 <?php
00002 $iOldErrorReproting = error_reporting();
00003 error_reporting($iOldErrorReproting & ~E_STRICT);
00004 
00005 $sPathExtra = getShopBasePath()."core/openid";
00006 $sPath = ini_get('include_path');
00007 $sPath = $sPath . PATH_SEPARATOR . $sPathExtra;
00008 ini_set('include_path', $sPath);
00009 
00010 if ( (PHP_OS == "WINNT") && !defined('Auth_OpenID_RAND_SOURCE') ) {
00015     define('Auth_OpenID_RAND_SOURCE', null);
00016 }
00017 
00018 require_once "openid/Auth/OpenID/Consumer.php";
00019 require_once "openid/Auth/OpenID/FileStore.php";
00020 require_once "openid/Auth/OpenID/SReg.php";
00021 
00022 error_reporting($iOldErrorReproting);
00028 class oxOpenId extends oxBase
00029 {
00038     public function authenticateOid( $sOpenId, $sReturnUrl )
00039     {
00040         $myConfig = $this->getConfig();
00041         // create OpenID consumer
00042         $oConsumer = $this->_getConsumer();
00043     
00044         // begin sign-in process
00045         // creates an authentication request to the OpenID provider
00046         $oAuth = $oConsumer->begin($sOpenId);
00047         if ( !$oAuth ) {
00048             //not valid OpenId
00049             $oEx = oxNew( 'oxUserException' );
00050             $oEx->setMessage( 'EXCEPTION_USER_NOVALIDOPENID' );
00051             throw $oEx;
00052         }
00053 
00054         // create request for registration data
00055         $oAuth->addExtension( Auth_OpenID_SRegRequest::build( array( 'email', 'fullname', 'gender', 'country' ), array( 'postcode' ) ) );
00056 
00057         // redirect to OpenID provider for authentication
00058         $sUrl = $oAuth->redirectURL( $myConfig->getShopUrl(), $sReturnUrl);
00059         oxUtils::getInstance()->redirect( $sUrl, false );
00060         
00061     }
00062 
00070     public function getOidResponse( $sReturnUrl )
00071     {
00072         // create OpenID consumer
00073         $oConsumer = $this->_getConsumer();
00074         $oResponse = $oConsumer->complete( $sReturnUrl );
00075 
00076         // authentication results
00077         if ( $oResponse->status == Auth_OpenID_SUCCESS ) {
00078             // get registration information
00079             $oSRreg = $this->_getResponse();
00080             $oRet   = $oSRreg->fromSuccessResponse( $oResponse );
00081             $aData  = $oRet->contents();
00082         } elseif ( $oResponse->status == Auth_OpenID_CANCEL ) {
00083             //Verification Cancelled by user
00084             $oEx = oxNew( 'oxUserException' );
00085             $oEx->setMessage( 'EXCEPTION_USER_OPENIDCANCELED' );
00086             throw $oEx;
00087         } else {
00088             //OpenID authentication failed
00089             $oEx = oxNew( 'oxUserException' );
00090             $oLang = oxLang::getInstance();
00091             $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_USER_OPENIDVALIDFAILED', $oLang->getBaseLanguage() ), $oResponse->message) );
00092             throw $oEx;
00093         }
00094         return $aData;
00095     }
00096 
00102     protected function _getConsumer()
00103     {
00104         $oConsumer = new Auth_OpenID_Consumer( $this->_getStore(), oxOpenIdSession::getInstance(), 'oxOpenIdGenericConsumer' );
00105 
00106         return $oConsumer;
00107     }
00108  
00114     protected function _getResponse()
00115     {
00116         $oSRreg = new Auth_OpenID_SRegResponse();
00117 
00118         return $oSRreg;
00119     }   
00120 
00127     protected function _getStore()
00128     {
00129         // create file storage area for OpenID data
00130         // $oStore = new Auth_OpenID_FileStore( oxConfig::getInstance()->getConfigParam( 'sCompileDir' ) );
00131         // create db storage area for OpenID data
00132         $oStore = new oxOpenIdDb();
00133         $oStore->createTables();
00134         return $oStore;
00135     }
00136 }

Generated on Tue Apr 21 15:45:44 2009 for OXID eShop CE by  doxygen 1.5.5