You are here

function openid_connect_generate_username in OpenID Connect / OAuth client 7

Same name and namespace in other branches
  1. 8 openid_connect.module \openid_connect_generate_username()

Generate a username for a new account.

Parameters

array $userinfo: The user claims.

Return value

string A unique username.

1 call to openid_connect_generate_username()
openid_connect_create_user in ./openid_connect.module
Creates a user indicating sub-id and login provider.

File

./openid_connect.module, line 389
A pluggable client implementation for the OpenID Connect protocol.

Code

function openid_connect_generate_username($sub, $userinfo, $client_name) {
  $name = 'oidc_' . $client_name . '_' . $sub;
  $candidates = array(
    '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; openid_connect_username_exists($name); $i++) {
    $name = $original . '_' . $i;
  }
  return $name;
}