Neos\Flow\Security\AccountRepository::findByAccountIdentifierAndAuthenticationProviderName PHP Method

findByAccountIdentifierAndAuthenticationProviderName() public method

Returns the account for a specific authentication provider with the given identifier
public findByAccountIdentifierAndAuthenticationProviderName ( string $accountIdentifier, string $authenticationProviderName ) : Account
$accountIdentifier string The account identifier
$authenticationProviderName string The authentication provider name
return Account
    public function findByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, $authenticationProviderName)
    {
        $query = $this->createQuery();
        return $query->matching($query->logicalAnd($query->equals('accountIdentifier', $accountIdentifier), $query->equals('authenticationProviderName', $authenticationProviderName)))->execute()->getFirst();
    }

Usage Example

 /**
  * Retrieves an existing user by the given username
  *
  * @param string $username The username
  * @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider"
  * @return User The user, or null if the user does not exist
  * @throws Exception
  * @api
  */
 public function getUser($username, $authenticationProviderName = null)
 {
     if ($authenticationProviderName !== null && isset($this->runtimeUserCache['a_' . $authenticationProviderName][$username])) {
         return $this->runtimeUserCache['a_' . $authenticationProviderName][$username];
     } elseif (isset($this->runtimeUserCache['u_' . $username])) {
         return $this->runtimeUserCache['u_' . $username];
     }
     $account = $this->accountRepository->findByAccountIdentifierAndAuthenticationProviderName($username, $authenticationProviderName ?: $this->defaultAuthenticationProviderName);
     if (!$account instanceof Account) {
         return null;
     }
     $user = $this->partyService->getAssignedPartyOfAccount($account);
     if (!$user instanceof User) {
         throw new Exception(sprintf('Unexpected user type "%s". An account with the identifier "%s" exists, but the corresponding party is not a Neos User.', get_class($user), $username), 1422270948);
     }
     if ($authenticationProviderName !== null) {
         if (!isset($this->runtimeUserCache['a_' . $authenticationProviderName])) {
             $this->runtimeUserCache['a_' . $authenticationProviderName] = [];
         }
         $this->runtimeUserCache['a_' . $authenticationProviderName][$username] = $user;
     } else {
         $this->runtimeUserCache['u_' . $username] = $user;
     }
     return $user;
 }