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 ( !defined('Auth_OpenID_RAND_SOURCE') ) {
00011     if ( $sRandSource = oxConfig::getInstance()->getConfigParam( 'sAuthOpenIdRandSource' ) ) {
00012         define( 'Auth_OpenID_RAND_SOURCE', $sRandSource );
00013     } elseif ( PHP_OS == 'WINNT' || ( @fopen( '/dev/urandom', 'r' ) === false ) ) {
00017         define( 'Auth_OpenID_RAND_SOURCE', null );
00018     }
00019 }
00020 
00021 require_once "openid/Auth/OpenID/Consumer.php";
00022 require_once "openid/Auth/OpenID/FileStore.php";
00023 require_once "openid/Auth/OpenID/SReg.php";
00024 
00025 error_reporting($iOldErrorReproting);
00031 class oxOpenId extends oxBase
00032 {
00041     public function authenticateOid( $sOpenId, $sReturnUrl )
00042     {
00043         $myConfig = $this->getConfig();
00044         // create OpenID consumer
00045         $oConsumer = $this->_getConsumer();
00046 
00047         // begin sign-in process
00048         // creates an authentication request to the OpenID provider
00049         $oAuth = $oConsumer->begin($sOpenId);
00050         if ( !$oAuth ) {
00051             //not valid OpenId
00052             $oEx = oxNew( 'oxUserException' );
00053             $oEx->setMessage( 'EXCEPTION_USER_NOVALIDOPENID' );
00054             throw $oEx;
00055         }
00056 
00057         // create request for registration data
00058         $oAuth->addExtension( Auth_OpenID_SRegRequest::build( array( 'email', 'fullname', 'gender', 'country' ), array( 'postcode' ) ) );
00059 
00060         // redirect to OpenID provider for authentication
00061         $sUrl = $oAuth->redirectURL( $myConfig->getShopUrl(), $sReturnUrl);
00062         oxUtils::getInstance()->redirect( $sUrl, false );
00063 
00064     }
00065 
00073     public function getOidResponse( $sReturnUrl )
00074     {
00075         // create OpenID consumer
00076         $oConsumer = $this->_getConsumer();
00077         $oResponse = $oConsumer->complete( $sReturnUrl );
00078 
00079         // authentication results
00080         if ( $oResponse->status == Auth_OpenID_SUCCESS ) {
00081             // get registration information
00082             $oSRreg = $this->_getResponse();
00083             $oRet   = $oSRreg->fromSuccessResponse( $oResponse );
00084             $aData  = $oRet->contents();
00085         } elseif ( $oResponse->status == Auth_OpenID_CANCEL ) {
00086             //Verification Cancelled by user
00087             $oEx = oxNew( 'oxUserException' );
00088             $oEx->setMessage( 'EXCEPTION_USER_OPENIDCANCELED' );
00089             throw $oEx;
00090         } else {
00091             //OpenID authentication failed
00092             $oEx = oxNew( 'oxUserException' );
00093             $oLang = oxLang::getInstance();
00094             $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_USER_OPENIDVALIDFAILED', $oLang->getBaseLanguage() ), $oResponse->message) );
00095             throw $oEx;
00096         }
00097         return $aData;
00098     }
00099 
00105     protected function _getConsumer()
00106     {
00107         $oConsumer = new Auth_OpenID_Consumer( $this->_getStore(), oxOpenIdSession::getInstance(), 'oxOpenIdGenericConsumer' );
00108 
00109         return $oConsumer;
00110     }
00111 
00117     protected function _getResponse()
00118     {
00119         $oSRreg = new Auth_OpenID_SRegResponse();
00120 
00121         return $oSRreg;
00122     }
00123 
00130     protected function _getStore()
00131     {
00132         // create file storage area for OpenID data
00133         // $oStore = new Auth_OpenID_FileStore( oxConfig::getInstance()->getConfigParam( 'sCompileDir' ) );
00134         // create db storage area for OpenID data
00135         $oStore = new oxOpenIdDb();
00136         $oStore->createTables();
00137         return $oStore;
00138     }
00139 }

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5