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
00042 $oConsumer = $this->_getConsumer();
00043
00044
00045
00046 $oAuth = $oConsumer->begin($sOpenId);
00047 if ( !$oAuth ) {
00048
00049 $oEx = oxNew( 'oxUserException' );
00050 $oEx->setMessage( 'EXCEPTION_USER_NOVALIDOPENID' );
00051 throw $oEx;
00052 }
00053
00054
00055 $oAuth->addExtension( Auth_OpenID_SRegRequest::build( array( 'email', 'fullname', 'gender', 'country' ), array( 'postcode' ) ) );
00056
00057
00058 $sUrl = $oAuth->redirectURL( $myConfig->getShopUrl(), $sReturnUrl);
00059 oxUtils::getInstance()->redirect( $sUrl, false );
00060
00061 }
00062
00070 public function getOidResponse( $sReturnUrl )
00071 {
00072
00073 $oConsumer = $this->_getConsumer();
00074 $oResponse = $oConsumer->complete( $sReturnUrl );
00075
00076
00077 if ( $oResponse->status == Auth_OpenID_SUCCESS ) {
00078
00079 $oSRreg = $this->_getResponse();
00080 $oRet = $oSRreg->fromSuccessResponse( $oResponse );
00081 $aData = $oRet->contents();
00082 } elseif ( $oResponse->status == Auth_OpenID_CANCEL ) {
00083
00084 $oEx = oxNew( 'oxUserException' );
00085 $oEx->setMessage( 'EXCEPTION_USER_OPENIDCANCELED' );
00086 throw $oEx;
00087 } else {
00088
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
00130
00131
00132 $oStore = new oxOpenIdDb();
00133 $oStore->createTables();
00134 return $oStore;
00135 }
00136 }