fix: [user enrollment] fixed via KC

pull/101/head
iglocska 2022-05-17 10:16:47 +02:00
parent a88318c5df
commit 398307e414
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 17 additions and 11 deletions

View File

@ -150,15 +150,12 @@ class AuthKeycloakBehavior extends Behavior
foreach ($roles as $role) {
$rolesParsed[$role['name']] = $role['id'];
}
$this->createUser($user, $clientId, $rolesParsed);
if ($this->createUser($user, $clientId, $rolesParsed)) {
$logChange = [
'username' => $user['username'],
'individual_id' => $user['individual']['id'],
'role_id' => $user['role']['id']
];
if (!$response->isOk()) {
$logChange['code'] = $response->getStatusCode();
$logChange['error_body'] = $response->getStringBody();
$this->_table->auditLogs()->insert([
'request_action' => 'enrollUser',
'model' => 'User',
@ -167,6 +164,11 @@ class AuthKeycloakBehavior extends Behavior
'changed' => $logChange
]);
} else {
$logChange = [
'username' => $user['username'],
'individual_id' => $user['individual']['id'],
'role_id' => $user['role']['id']
];
$this->_table->auditLogs()->insert([
'request_action' => 'enrollUser',
'model' => 'User',
@ -406,10 +408,14 @@ class AuthKeycloakBehavior extends Behavior
]);
}
$newUser = $this->restApiRequest('%s/admin/realms/%s/users?username=' . urlencode($user['username']), [], 'get');
$user['id'] = json_decode($newUser->getStringBody(), true);
if (empty($user['id'])) {
$users = json_decode($newUser->getStringBody(), true);
if (empty($users[0]['id'])) {
return false;
}
if (is_array($users[0]['id'])) {
$users[0]['id'] = $users[0]['id'][0];
}
$user['id'] = $users[0]['id'];
$this->assignRolesToUser($user, $rolesParsed, $clientId);
return true;
}