encodeResponse() public method

Encodes as response in the appropriate format suitable for sending to the user agent.
public encodeResponse ( $response )
Beispiel #1
0
 /**
  * Send an OpenID response.
  *
  * This function never returns.
  *
  * @param Auth_OpenID_ServerResponse $response  The response.
  */
 private function sendResponse(Auth_OpenID_ServerResponse $response)
 {
     SimpleSAML_Logger::debug('openidProvider::sendResponse');
     $webresponse = $this->server->encodeResponse($response);
     if ($webresponse->code !== 200) {
         header('HTTP/1.1 ' . $webresponse->code, TRUE, $webresponse->code);
     }
     foreach ($webresponse->headers as $k => $v) {
         header($k . ': ' . $v);
     }
     header('Connection: Close');
     print $webresponse->body;
     exit(0);
 }
Beispiel #2
0
 public function executeTrust(sfWebRequest $request)
 {
     opApplicationConfiguration::registerJanRainOpenID();
     require_once 'Auth/OpenID/Server.php';
     require_once 'Auth/OpenID/FileStore.php';
     require_once 'Auth/OpenID/SReg.php';
     require_once 'Auth/OpenID/AX.php';
     $info = unserialize($_SESSION['request']);
     $this->forward404Unless($info);
     $trusted = $request->hasParameter('trust') || $request->hasParameter('permanent');
     if (!$trusted) {
         unset($_SESSION['request']);
         $url = $info->getCancelURL();
         $this->redirect($url);
     }
     $reqUrl = $this->getController()->genUrl('OpenID/member?id=' . $this->getUser()->getMemberId(), true);
     if (!$info->idSelect()) {
         $this->forward404Unless($reqUrl === $info->identity, 'request:' . $reqUrl . '/identity:' . $info->identity);
     }
     unset($_SESSION['request']);
     $server = new Auth_OpenID_Server(new Auth_OpenID_FileStore(sfConfig::get('sf_cache_dir')), $info->identity);
     $response = $info->answer(true, null, $reqUrl);
     $sregRequest = Auth_OpenID_SRegRequest::fromOpenIDRequest($info);
     $axRequest = Auth_OpenID_AX_FetchRequest::fromOpenIDRequest($info);
     $allowedProfiles = $request->getParameter('profiles', array());
     $requiredProfiles = $this->createListOfRequestedProfiles($sregRequest, $axRequest);
     $rejectedProfiles = array_diff_key($requiredProfiles, array_flip($allowedProfiles));
     if (in_array(true, $rejectedProfiles)) {
         $url = $info->getCancelURL();
         $this->redirect($url);
     }
     if ($sregRequest) {
         $sregExchange = new opOpenIDProfileExchange('sreg', $this->getUser()->getMember());
         $sregResp = Auth_OpenID_SRegResponse::extractResponse($sregRequest, $sregExchange->getData($allowedProfiles));
         $response->addExtension($sregResp);
     }
     if ($axRequest && !$axRequest instanceof Auth_OpenID_AX_Error) {
         $axResp = new Auth_OpenID_AX_FetchResponse();
         $axExchange = new opOpenIDProfileExchange('ax', $this->getUser()->getMember());
         $userData = $axExchange->getData($allowedProfiles);
         foreach ($axRequest->requested_attributes as $k => $v) {
             if (!empty($userData[$k])) {
                 $axResp->addValue($k, $userData[$k]);
             }
         }
         $response->addExtension($axResp);
     }
     $log = Doctrine::getTable('OpenIDTrustLog')->log($info->trust_root, $this->getUser()->getMemberId());
     if ($request->hasParameter('permanent')) {
         $log->is_permanent = true;
         $log->save();
     }
     $response = $server->encodeResponse($response);
     return $this->writeResponse($response);
 }
 private function _sendResponse(Auth_OpenID_Server $server, Auth_OpenID_ServerResponse $response)
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNeverRender(true);
     $webresponse = $server->encodeResponse($response);
     if ($webresponse->code != AUTH_OPENID_HTTP_OK) {
         $this->_response->setRawHeader(sprintf("HTTP/1.1 %d ", $webresponse->code), true, $webresponse->code);
     }
     foreach ($webresponse->headers as $k => $v) {
         if ($k == 'location') {
             $this->_response->setRedirect($v);
         } else {
             $this->_response->setHeader($k, $v);
         }
     }
     $this->_response->setHeader('Connection', 'close');
     $this->_response->appendBody($webresponse->body);
 }