Hello Everyone!!!, Is Somebody manage to add flash error message in authentication plugin when trying to access a action not include in addUnauthenticatedActions?
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
{
$authenticationService = new AuthenticationService([
‘unauthenticatedRedirect’ => Router::url([‘prefix’ => false, ‘controller’ => ‘Users’, ‘action’ => ‘login’]),
‘queryParam’ => ‘redirect’,
]);
// Load identifiers, ensure we check email and password fields
$authenticationService->loadIdentifier('Authentication.Password', [
'fields' => [
'username' => ['username', 'email'],
'password' => 'password',
],
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'Users',
'finder' => 'auth',
],
]);
// Load the authenticators, you want session first
$authenticationService->loadAuthenticator('Authentication.Session');
// Configure form data check to pick email and password
$authenticationService->loadAuthenticator('Authentication.Form', [
'fields' => [
'username' => 'username',
'password' => 'password',
],
'loginUrl' => Router::url(['prefix' => false, 'controller' => 'Users', 'action' => 'login']),
]);
$authenticationService->loadIdentifier('RememberMe.RememberMeToken', [
'fields' => [
'username' => 'email',
'password' => 'password',
],
'userTokenFieldName' => 'remember_me_token',
'tokenStorageModel' => 'RememberMe.RememberMeTokens',
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'Users',
],
]);
$authenticationService->loadAuthenticator('RememberMe.Cookie', [
'fields' => [
'username' => 'email',
'password' => 'password',
],
'loginUrl' => Router::url(['prefix' => false, 'controller' => 'Users', 'action' => 'login']),
'rememberMeField' => 'remember_me',
'cookie' => [
'name' => 'rememberMe',
'expires' => '+30 days',
'secure' => true,
'httpOnly' => true,
],
'tokenStorageModel' => 'RememberMe.RememberMeTokens',
'always' => false,
'dropExpiredToken' => true,
]);
return $authenticationService;
}