ZF-Commons / ZfcUser

A generic user registration and authentication module for ZF2. Supports Zend\Db and Doctrine2. (Formerly EdpUser)
BSD 3-Clause "New" or "Revised" License
497 stars 343 forks source link

Integration with Zend\Json\Server #662

Open citrususer4 opened 7 years ago

citrususer4 commented 7 years ago
$app = Application::init(require 'config/application.config.php');
$service = $app->bootstrap()->getServiceManager();
$auth = $service->get('zfcuser_auth_service');
$auth->hasIdentity();

This work good. But how to get adapter $adapter = $auth->getAuthAdapter(); Call to undefined method Zend\Authentication\AuthenticationService::getAuthAdapter():

citrususer4 commented 7 years ago

After many experiments, something happened. I do not know how much the right decision but it works

$adapter = $service->get('ZfcUser\Authentication\Adapter\AdapterChain');
$request = new \Zend\Http\Request();
$request->setMethod('POST');
$request->getPost()->set('identity', $identity)->set('credential', $credential);
$result = $adapter->prepareForAuthentication($request);
session_id($_SERVER['HTTP_PHPSESSID']);
$result = $auth->authenticate($adapter);
return $result->isValid();