You are here

public function OpenIDConnect::createUser in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x src/OpenIDConnect.php \Drupal\openid_connect\OpenIDConnect::createUser()

Create a user indicating sub-id and login provider.

Parameters

string $sub: The subject identifier.

array $userinfo: The user claims, containing at least 'email'.

string $client_name: The machine name of the client.

int $status: The initial user status.

Return value

\Drupal\user\UserInterface|false The user object or FALSE on failure.

1 call to OpenIDConnect::createUser()
OpenIDConnect::completeAuthorization in src/OpenIDConnect.php
Complete the authorization after tokens have been retrieved.

File

src/OpenIDConnect.php, line 497

Class

OpenIDConnect
Main service of the OpenID Connect module.

Namespace

Drupal\openid_connect

Code

public function createUser($sub, array $userinfo, $client_name, $status = 1) {

  /** @var \Drupal\user\UserInterface $account */
  $account = $this->userStorage
    ->create([
    'name' => $this
      ->generateUsername($sub, $userinfo, $client_name),
    'pass' => user_password(),
    'mail' => $userinfo['email'],
    'init' => $userinfo['email'],
    'status' => $status,
    'openid_connect_client' => $client_name,
    'openid_connect_sub' => $sub,
  ]);
  $account
    ->save();
  return $account;
}