You are here

public function OpenIDConnectAuthmap::userLoadBySub in OpenID Connect / OAuth client 8

Loads a user based on a sub-id and a login provider.

Parameters

string $sub: The remote subject identifier.

string $client_name: The client name.

Return value

object|bool A user account object or FALSE

File

src/OpenIDConnectAuthmap.php, line 97

Class

OpenIDConnectAuthmap
The OpenID Connect authmap service.

Namespace

Drupal\openid_connect

Code

public function userLoadBySub($sub, $client_name) {
  $result = $this->connection
    ->select('openid_connect_authmap', 'a')
    ->fields('a', [
    'uid',
  ])
    ->condition('client_name', $client_name, '=')
    ->condition('sub', $sub, '=')
    ->execute();
  foreach ($result as $record) {

    /** @var \Drupal\user\Entity\User $account */
    $account = $this->userStorage
      ->load($record->uid);
    if (is_object($account)) {
      return $account;
    }
  }
  return FALSE;
}