You are here

protected function AuthController::auth0UpdateFields in Auth0 Single Sign On 8.2

Update the $user profile attributes based on the auth0 field mappings.

Parameters

array $userInfo: The user info array.

\Drupal\user\Entity\User $user: The Drupal user entity.

array $edit: The edit array.

1 call to AuthController::auth0UpdateFields()
AuthController::auth0UpdateFieldsAndRoles in src/Controller/AuthController.php
Update the Auth fields.

File

src/Controller/AuthController.php, line 770
Contains \Drupal\auth0\Controller\AuthController.

Class

AuthController
Controller routines for auth0 authentication.

Namespace

Drupal\auth0\Controller

Code

protected function auth0UpdateFields(array $userInfo, User $user, array &$edit) {
  $auth0_claim_mapping = $this->config
    ->get('auth0_claim_mapping');
  if (isset($auth0_claim_mapping) && !empty($auth0_claim_mapping)) {

    // For each claim mapping, lookup the value, otherwise set to blank.
    $mappings = $this
      ->auth0PipeListToArray($auth0_claim_mapping);

    // Remove mappings handled automatically by the module.
    $skip_mappings = [
      'uid',
      'name',
      'mail',
      'init',
      'is_new',
      'status',
      'pass',
    ];
    foreach ($mappings as $mapping) {
      $this->auth0Logger
        ->notice('mapping ' . $mapping);
      $key = $mapping[1];
      if (in_array($key, $skip_mappings)) {
        $this->auth0Logger
          ->notice('skipping mapping handled already by Auth0 module ' . $mapping);
      }
      else {
        $value = isset($userInfo[$mapping[0]]) ? $userInfo[$mapping[0]] : '';
        $current_value = $user
          ->get($key)->value;
        if ($current_value === $value) {
          $this->auth0Logger
            ->notice('value is unchanged ' . $key);
        }
        else {
          $this->auth0Logger
            ->notice('value changed ' . $key . ' from [' . $current_value . '] to [' . $value . ']');
          $edit[$key] = $value;
          $user
            ->set($key, $value);
        }
      }
    }
  }
}