ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 9641


Ignore:
Timestamp:
Dec 23, 2008, 5:16:34 PM (12 years ago)
Author:
ebihara
Message:

#3221:changed using library for OpenID Cosumer Zend_OpenID to JanRain? PHP OpenID Library

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opAuthOpenIDPlugin/trunk/lib/sfOpenPNEAuthForm_OpenID.class.php

    r9634 r9641  
    1313  {
    1414    $this->setWidget('openid_identifier', new sfWidgetFormInput());
    15     $this->setValidator('openid_identifier', new sfValidatorUrl(array('required' => false)));
     15    $this->setValidator('openid_identifier', new sfValidatorString(array('required' => false)));
    1616    $this->widgetSchema->setLabel('openid_identifier', 'OpenID');
    1717
     
    2525  public function handleRequest($validator, $value, $arguments = array())
    2626  {
    27     sfOpenPNEApplicationConfiguration::registerZend();
    28     $consumer = new Zend_OpenID_Consumer();
     27    $this->registerJanRainOpenID();
     28    $consumer = new Auth_OpenID_Consumer(new Auth_OpenID_FileStore(sfConfig::get('sf_cache_dir')));
     29    $currentURL = sfContext::getInstance()->getRequest()->getUri();
    2930
    3031    if (isset($_GET['openid_mode']))
    3132    {
    32       if (!$consumer->verify($_GET, $id))
     33      $response = $consumer->complete($currentURL);
     34
     35      if ($response->status === Auth_OpenID_CANCEL)
    3336      {
    34         throw new sfValidatorError($validator, $consumer->getError());
     37        throw new sfValidatorError($validator, 'Verification cancelled.');
    3538      }
    36 
    37       $value['id'] = $id;
    38 
    39       return $value;
     39      elseif ($response->status === Auth_OpenID_FAILURE)
     40      {
     41        throw new sfValidatorError($validator, 'Authentication failed: '.$response->message);
     42      }
     43      elseif ($response->status === Auth_OpenID_SUCCESS)
     44      {
     45        $value['id'] = $response->getDisplayIdentifier();
     46        return $value;
     47      }
    4048    }
    4149
    42     if (!$consumer->login($value['openid_identifier']))
     50    $authRequest = $consumer->begin($value['openid_identifier']);
     51    if (!$authRequest)
    4352    {
    44       throw new sfValidatorError($validator, $consumer->getError());
     53      throw new sfValidatorError($validator, 'Authentication error: not a valid OpenID.');
    4554    }
    4655
    47     throw new LogicException('The process encountered an unknown failure.');
     56    // for OpenID1
     57    if ($authRequest->shouldSendRedirect())
     58    {
     59      $toUrl = $authRequest->redirectURL($currentURL, $currentURL);
     60      if (Auth_OpenID::isFailure($toUrl))
     61      {
     62        throw new sfValidatorError($validator, 'Could not redirect to the server: '.$toUrl->message);
     63      }
     64      else
     65      {
     66        header('Location: '.$toUrl);
     67        exit;
     68      }
     69    }
     70
     71    // for OpenID2
     72    $formHTML = $authRequest->htmlMarkup($currentURL, $currentURL);
     73    if (Auth_OpenID::isFailure($formHTML))
     74    {
     75      throw new sfValidatorError($validator, 'Could not redirect to the server: '.$formHTML->message);
     76    }
     77
     78    // We got a valid HTML contains JavaScript to redirect to the OpenID provider's site.
     79    // This HTML must not include any contents from symfony, so this script will stop here.
     80    echo $formHTML;
     81    exit;
    4882  }
    4983
     
    5993    return 'OpenID';
    6094  }
     95
     96  public function registerJanRainOpenID()
     97  {
     98    $DS = DIRECTORY_SEPARATOR;
     99    $openidPath = sfConfig::get('sf_lib_dir').$DS.'vendor'.$DS.'php-openid'.$DS;  // ##PROJECT_LIB_DIR##/vendor/php-openid/
     100    set_include_path($openidPath.PATH_SEPARATOR.get_include_path());
     101
     102    require_once 'Auth/OpenID/Consumer.php';
     103    require_once 'Auth/OpenID/FileStore.php';
     104    require_once 'Auth/OpenID/SReg.php';
     105  }
    61106}
Note: See TracChangeset for help on using the changeset viewer.