2008年11月12日星期三

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

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

没有评论: