Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session is started by this module even in CLI mode #518

Open
ojhaujjwal opened this issue Sep 1, 2014 · 6 comments
Open

Session is started by this module even in CLI mode #518

ojhaujjwal opened this issue Sep 1, 2014 · 6 comments

Comments

@ojhaujjwal
Copy link
Contributor

ZfcUser\Authentication\Storage\Db starts session when isEmpty method is called n session is not started. The problem appears when the current request is not HttpRequest (i.e. CliRequest). Is this an intended behaviour?

@ojhaujjwal
Copy link
Contributor Author

ping @Danielss89

@Ocramius
Copy link
Contributor

@ojhaujjwal what happens in that case? failure? error?

@ojhaujjwal
Copy link
Contributor Author

Generally, there is no error but I don't see any point in starting session in CLI mode. We may check if request is HttpRequest or CliRequest.

    public function isEmpty()
    {
        $request = $this->getServiceManager()->get('Request');
        if (!$request instanceof HttpRequest) {
            return true;
        }

        // previously the session was started here in CLI
        if ($this->getStorage()->isEmpty()) {
            return true;
        }
        $identity = $this->read();
        if ($identity === null) {
            $this->clear();
            return true;
        }

        return false;
    }

@Ocramius
Copy link
Contributor

@ojhaujjwal yes, but I'm wondering if this shouldn't simply go back to Zend\Session instead...

@ojhaujjwal
Copy link
Contributor Author

@Ocramius Yes. I don't know how but I think it will more easier if this is handled by Zend\Session out-of-the-box.

@adamlundrigan
Copy link
Contributor

@Danielss89 this is essentially a duplicate of #513

I've run into this issue myself with ZfcUser 1.x and I worked around it by creating a separate bootstrap file to use when running console commands with this addition above $app->run():

use ZfcUser\Authentication\Adapter\AdapterChain;
use ZfcUser\Authentication\Adapter\AdapterChainEvent;
use Zend\Authentication\Result;

$authService = $app->getServiceManager()->get('zfcuser_auth_service');
$authAdapterChain = new AdapterChain();
$authAdapterChain->getEventManager()->attach('authenticate', function(AdapterChainEvent $e) {
    $e->setCode(Result::SUCCESS)
      ->setIdentity(1);  // This forces the auth'd user to our consoleadmin user
});
$authAdapterChain->prepareForAuthentication(new \Zend\Console\Request());
$authService->authenticate($authAdapterChain);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants