applicationState->isPortal()) { $method = $this->getForPortal($this->applicationState->getPortal()); if ($method) { return $method; } return $this->getDefaultForPortal(); } return $this->configDataProvider->getDefaultAuthenticationMethod(); } /** * Get an authentication method for portals. The method that is applied via the authentication provider link. * If no provider, then returns null. */ public function getForPortal(Portal $portal): ?string { $providerId = $portal->getAuthenticationProvider()?->getId(); if (!$providerId) { return null; } /** @var ?AuthenticationProvider $provider */ $provider = $this->entityManager->getEntityById(AuthenticationProvider::ENTITY_TYPE, $providerId); if (!$provider) { throw new RuntimeException("No authentication provider for portal."); } $method = $provider->getMethod(); if (!$method) { throw new RuntimeException("No method in authentication provider."); } return $method; } /** * Get a default authentication method for portals. Should be used if a portal does not have * an authentication provider. */ private function getDefaultForPortal(): string { $method = $this->configDataProvider->getDefaultAuthenticationMethod(); $allow = $this->metadata->get(['authenticationMethods', $method, 'portalDefault']); if (!$allow) { return Espo::NAME; } return $method; } }