$processors]); $this->loadIdentifiers($service); $this->loadAuthenticators($service); $this->loadTwoFactorAuthenticator($service, $processors); return $service; } /** * Load the indentifiers defined at config Auth.Identifiers * * @param \CakeDC\Auth\Authentication\AuthenticationService $service Authentication service to load identifiers * @return void */ protected function loadIdentifiers($service) { $identifiers = Configure::read('Auth.Identifiers'); foreach ($identifiers as $key => $item) { [$identifier, $options] = $this->_getItemLoadData($item, $key); $service->loadIdentifier($identifier, $options); } } /** * Load the authenticators defined at config Auth.Authenticators * * @param \CakeDC\Auth\Authentication\AuthenticationService $service Authentication service to load identifiers * @return void */ protected function loadAuthenticators($service) { $authenticators = Configure::read('Auth.Authenticators'); foreach ($authenticators as $key => $item) { [$authenticator, $options] = $this->_getItemLoadData($item, $key); $service->loadAuthenticator($authenticator, $options); } } /** * Load the CakeDC/Auth.TwoFactor based on config OneTimePasswordAuthenticator.login * * @param \CakeDC\Auth\Authentication\AuthenticationService $service Authentication service to load identifiers * @param \CakeDC\Auth\Authentication\TwoFactorProcessorCollection $processors TwoFactorProcessors collection * @return void */ protected function loadTwoFactorAuthenticator($service, $processors) { if (collection($processors)->some(fn($processor) => $processor->enabled())) { $service->loadAuthenticator('CakeDC/Auth.TwoFactor', [ 'skipTwoFactorVerify' => true, ]); } } /** * @param mixed $item Item configuration or className * @param string $key Item array key. * @return array */ protected function _getItemLoadData($item, $key) { $options = []; if (!is_array($item)) { return [$item, $options]; } $options = $item; if (!isset($options['className'])) { throw new \InvalidArgumentException( __d('cake_d_c/users', 'Property {0}.className should be defined', $key), ); } $className = $options['className']; unset($options['className']); return [$className, $options]; } }