Skip to content
Permalink
Browse files

Trigger Auth.afterIdentify even for stateless authentication

  • Loading branch information...
ADmad committed Dec 2, 2015
1 parent f1f7c3f commit 754f4a24e8760b63b738845ad98bb847139752d9
@@ -697,6 +697,10 @@ protected function _getUser()
$result = $auth->getUser($this->request);
if (!empty($result) && is_array($result)) {
$this->_authenticationProvider = $auth;
$event = $this->dispatchEvent('Auth.afterIdentify', [$result]);
if ($event->result !== null) {
$result = $event->result;
}
$this->storage()->write($result);
return true;
}
@@ -20,6 +20,7 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
@@ -1163,6 +1164,36 @@ public function testEventTriggering()
$this->assertEquals($expected, $user);
}
/**
* testAfterIdentifyForStatelessAuthentication
*
* @return void
* @triggers Controller.startup $this->Controller
*/
public function testAfterIdentifyForStatelessAuthentication()
{
$event = new Event('Controller.startup', $this->Controller);
$url = '/auth_test/add';
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->env('PHP_AUTH_USER', 'mariano');
$this->Auth->request->env('PHP_AUTH_PW', 'cake');
$this->Auth->config('authenticate', [
'Basic' => ['userModel' => 'AuthUsers']
]);
$this->Auth->config('storage', 'Memory');
EventManager::instance()->on('Auth.afterIdentify', function ($event) {
$user = $event->data[0];
$user['from_callback'] = true;
return $user;
});
$this->Auth->startup($event);
$this->assertEquals('mariano', $this->Auth->user('username'));
$this->assertTrue($this->Auth->user('from_callback'));
}
/**
* test setting user info to session.
*

0 comments on commit 754f4a2

Please sign in to comment.
You can’t perform that action at this time.