You are here

public function KeycloakRoleMatcher::getGroups in Keycloak OpenID Connect 8

Retrieve Keycloak groups from user information.

Parameters

string $attribute: Keycloak groups claim identifier.

array $userinfo: User info array as returned by \Drupal\keycloak\Plugin\OpenIDConnectClient\Keycloak::retrieveUserInfo().

Return value

array Extracted user groups.

1 call to KeycloakRoleMatcher::getGroups()
KeycloakRoleMatcher::applyRoleRules in src/Service/KeycloakRoleMatcher.php
Applies user role rules to the given user account.

File

src/Service/KeycloakRoleMatcher.php, line 129

Class

KeycloakRoleMatcher
Role matcher service.

Namespace

Drupal\keycloak\Service

Code

public function getGroups($attribute, array $userinfo) {

  // Whether the user information is empty.
  if (empty($userinfo)) {

    // No group attribute. Return empty array.
    return [];
  }

  // Walk the attribute path to retrieve the user groups.
  $attribute_path = explode('.', $attribute);
  while (!empty($attribute_path)) {
    $segment = array_shift($attribute_path);
    if (isset($userinfo[$segment])) {
      $userinfo = $userinfo[$segment];
    }
    else {
      $userinfo = [];
      break;
    }
  }
  return $userinfo;
}