You are here

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

Get a list of external OIDC accounts connected to this Drupal account.

Parameters

object $account: A Drupal user entity.

string $client_name: An optional client name.

Return value

array An array of 'sub' properties keyed by the client name.

1 call to OpenIDConnectAuthmap::getConnectedAccounts()
OpenIDConnectAuthmap::createAssociation in src/OpenIDConnectAuthmap.php
Create a local to remote account association.

File

src/OpenIDConnectAuthmap.php, line 124

Class

OpenIDConnectAuthmap
The OpenID Connect authmap service.

Namespace

Drupal\openid_connect

Code

public function getConnectedAccounts($account, $client_name = '') {
  $query = $this->connection
    ->select('openid_connect_authmap', 'a')
    ->fields('a', [
    'client_name',
    'sub',
  ])
    ->condition('uid', $account
    ->id());
  if (!empty($client_name)) {
    $query
      ->condition('client_name', $client_name, '=');
  }
  $result = $query
    ->execute();
  $authmaps = [];
  foreach ($result as $record) {
    $client = $record->client_name;
    $sub = $record->sub;
    $authmaps[$client] = $sub;
  }
  return $authmaps;
}