public function OpenIDConnect::generateUsername in OpenID Connect / OAuth client 8
Same name and namespace in other branches
- 2.x src/OpenIDConnect.php \Drupal\openid_connect\OpenIDConnect::generateUsername()
Generate a username for a new account.
Parameters
string $sub: The subject identifier.
array $userinfo: The user claims.
string $client_name: The client identifier.
Return value
string A unique username.
1 call to OpenIDConnect::generateUsername()
- OpenIDConnect::createUser in src/
OpenIDConnect.php - Create a user indicating sub-id and login provider.
File
- src/
OpenIDConnect.php, line 536
Class
- OpenIDConnect
- Main service of the OpenID Connect module.
Namespace
Drupal\openid_connectCode
public function generateUsername($sub, array $userinfo, $client_name) {
$name = 'oidc_' . $client_name . '_' . md5($sub);
$candidates = [
'preferred_username',
'name',
];
foreach ($candidates as $candidate) {
if (!empty($userinfo[$candidate])) {
$name = trim($userinfo[$candidate]);
break;
}
}
// Ensure there are no duplicates.
for ($original = $name, $i = 1; $this
->usernameExists($name); $i++) {
$name = $original . '_' . $i;
}
return $name;
}