You are here

public function ExternalAuth::linkExistingAccount in External Authentication 8

Same name and namespace in other branches
  1. 2.0.x src/ExternalAuth.php \Drupal\externalauth\ExternalAuth::linkExistingAccount()

Link a pre-existing Drupal user to a given authname.

Parameters

string $authname: The unique, external authentication name provided by authentication provider.

string $provider: The module providing external authentication.

\Drupal\user\UserInterface $account: The existing Drupal account to link.

Overrides ExternalAuthInterface::linkExistingAccount

File

src/ExternalAuth.php, line 172

Class

ExternalAuth
Class ExternalAuth.

Namespace

Drupal\externalauth

Code

public function linkExistingAccount($authname, $provider, UserInterface $account) {

  // If a mapping (for the same provider) to this account already exists, we
  // silently skip saving this auth mapping.
  if (!$this->authmap
    ->get($account
    ->id(), $provider)) {
    $authmap_event = $this->eventDispatcher
      ->dispatch(ExternalAuthEvents::AUTHMAP_ALTER, new ExternalAuthAuthmapAlterEvent($provider, $authname, $account
      ->getAccountName(), NULL));
    $this->authmap
      ->save($account, $provider, $authmap_event
      ->getAuthname(), $authmap_event
      ->getData());
  }
}