You are here

public function OpenIDConnect::createUser in OpenID Connect / OAuth client 2.x

Same name and namespace in other branches
  1. 8 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|null The user object or null 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 520

Class

OpenIDConnect
Main service of the OpenID Connect module.

Namespace

Drupal\openid_connect

Code

public function createUser(string $sub, array $userinfo, string $client_name, int $status = 1) : ?UserInterface {
  $account_data = [
    'name' => $this
      ->generateUsername($sub, $userinfo, $client_name),
    'mail' => $userinfo['email'],
    'init' => $userinfo['email'],
    'status' => $status,
  ];
  return $this->externalAuth
    ->register($sub, 'openid_connect.' . $client_name, $account_data);
}