config = $config; $this->metadata = $metadata; } /** * A period for max failed attempts checking. */ public function getFailedAttemptsPeriod(): string { return $this->config->get('authFailedAttemptsPeriod', self::FAILED_ATTEMPTS_PERIOD); } /** * Max failed log in attempts. */ public function getMaxFailedAttemptNumber(): int { return $this->config->get('authMaxFailedAttemptNumber', self::MAX_FAILED_ATTEMPT_NUMBER); } /** * Auth token secret won't be created. Can be reasonable for a custom AuthTokenManager implementation. */ public function isAuthTokenSecretDisabled(): bool { return (bool) $this->config->get('authTokenSecretDisabled'); } /** * A maintenance mode. Only admin can log in. */ public function isMaintenanceMode(): bool { return (bool) $this->config->get('maintenanceMode'); } /** * Whether 2FA is enabled. */ public function isTwoFactorEnabled(): bool { return (bool) $this->config->get('auth2FA'); } /** * Allowed methods of 2FA. * * @return array */ public function getTwoFactorMethodList(): array { return $this->config->get('auth2FAMethodList') ?? []; } /** * A user won't be able to have multiple active auth tokens simultaneously. */ public function preventConcurrentAuthToken(): bool { return (bool) $this->config->get('authTokenPreventConcurrent'); } /** * A default authentication method. */ public function getDefaultAuthenticationMethod(): string { return $this->config->get('authenticationMethod', Espo::NAME); } /** * Whether an authentication method can be defined by request itself (in a header). */ public function authenticationMethodIsApi(string $authenticationMethod): bool { return (bool) $this->metadata->get(['authenticationMethods', $authenticationMethod, 'api']); } public function isAnotherUserDisabled(): bool { return (bool) $this->config->get('authAnotherUserDisabled'); } /** * @return MetadataParams[] */ public function getLoginMetadataParamsList(): array { $list = []; /** @var array> $data */ $data = $this->metadata->get(['authenticationMethods']) ?? []; foreach ($data as $method => $item) { $list[] = MetadataParams::fromRaw($method, $item); } return $list; } public function getMethodLoginMetadataParams(string $method): MetadataParams { /** @var ?array $data */ $data = $this->metadata->get(['authenticationMethods', $method]); if ($data === null) { throw new RuntimeException(); } return MetadataParams::fromRaw($method, $data); } }