You are here

public function OAuth2Storage::getStorageAccount in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x src/OAuth2Storage.php \Drupal\oauth2_server\OAuth2Storage::getStorageAccount()

Retrieve the account from the storage.

Parameters

string $username: The username or email address of the account.

Return value

\Drupal\user\UserInterface|bool The account loaded from the storage or false.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

2 calls to OAuth2Storage::getStorageAccount()
OAuth2Storage::checkUserCredentials in src/OAuth2Storage.php
Check user credentials.
OAuth2Storage::getUserDetails in src/OAuth2Storage.php
Get user details.

File

src/OAuth2Storage.php, line 96

Class

OAuth2Storage
Provides Drupal OAuth2 storage for the library.

Namespace

Drupal\oauth2_server

Code

public function getStorageAccount($username) {

  /** @var \Drupal\user\UserInterface[] $users */
  $users = $this->entityTypeManager
    ->getStorage('user')
    ->loadByProperties([
    'name' => $username,
  ]);
  if ($users) {
    return reset($users);
  }
  else {

    // An email address might have been supplied instead of the username.

    /** @var \Drupal\user\UserInterface[] $users */
    $users = $this->entityTypeManager
      ->getStorage('user')
      ->loadByProperties([
      'mail' => $username,
    ]);
    if ($users) {
      return reset($users);
    }
  }
  return FALSE;
}