2008年11月12日星期三

Re: [fw-auth] Problems with Zend Auth HTTP Basic authentication

Hi Aurelijus,

Glad I could help a little bit. The HTTP Auth adapter has always simply set the headers on the response object, and then relied on the Framework's request processing cycle to output those headers later. Essentially, it's not the adapter's responsibility to force the headers to be sent, since header management is one of the response object's jobs.

Regards,
Bryce Lohr


aurelijus@astdev.lt wrote:
Thanks Bryce,
I've just tried to add $response->sendHeaders(); below authenticate() and it seems it worked. However it is still strange, why Auth adapter doesn't send headers itself.
--
Aurelijus

On Wed, Nov 12, 2008 at 4:25 PM, Bryce Lohr <brycel@patientadvocate.org> wrote:
Hi Aurelijus,

On first glance, it appears that you have everything set up correctly. >From the dump shown, it looks like the headers are correctly being set in the response object, so the task would be to figure out why the headers aren't being sent.

Obvious check first: can you send headers with header()? Is output buffering enabled, or is error display turned off (so that a problem is being hidden)?

Next, can you send other headers to the browser via the response object? IIRC, the front controller simply loops over and outputs all the headers collected in the response object at the end of the request processing cycle. If other headers set by your application are being output properly, then I need to investigate why the HTTP Auth adapter's headers aren't being sent.

Hope this helps,
Bryce Lohr



aurelijus@astdev.lt wrote:
Hi,
I'm having a problem setting up the http basic authentication. 
I don't why but it just doesn't work for me. It seems that I miss something :)
So, I have an initializer plugin. Here is some code:
  public function dispatchLoopStartup (Zend_Controller_Request_Abstract $request)
    {
            $path     = ROOT_PATH . '/pass.txt';
            $resolver = new Zend_Auth_Adapter_Http_Resolver_File($path);
            $config = array(
                'accept_schemes' => 'basic',
                'realm'          => 'MyWebsite'
            );
            $adapter = new Zend_Auth_Adapter_Http($config);
            $adapter->setBasicResolver($resolver);
    $storage = new Zend_Auth_Storage_NonPersistent;
    Zend_Auth::getInstance()->setStorage($storage);
            $response = Zend_Controller_Front::getInstance()->getResponse();
            assert($request instanceof Zend_Controller_Request_Http);
            assert($response instanceof Zend_Controller_Response_Http);
            
            $adapter->setRequest($request);
            $adapter->setResponse($response);
            
            $result = Zend_Auth::getInstance()->authenticate($adapter);
            if (!$result->isValid()) {
Zend_Debug::dump($response->getHeaders());
            }
        }
    }

And the result of this is dumped headers and content that should be displayed only after authentication:
array(1) {
  [0] => array(3) {
    ["name"] => string(16) "Www-Authenticate"
    ["value"] => string(22) "Basic realm="MyWebsite""
    ["replace"] => bool(false)
  }
}

The main problem is that the authentication headers aren't even sent. I mean If I visit the page, the browser doesn't ask me for http authentication credentials.

Thanks for the help,
Aurelijus

没有评论: