fix: [keycloak] when enrolling users in keycloak, use the user organisation_id instead of the individual's first alias

pull/79/head
iglocska 2021-11-24 01:34:15 +01:00
parent 3cc857c42f
commit 92fee87a7f
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 5 additions and 6 deletions

View File

@ -98,7 +98,7 @@ class AuthKeycloakBehavior extends Behavior
{ {
$individual = $this->_table->Individuals->find()->where( $individual = $this->_table->Individuals->find()->where(
['id' => $data['individual_id']] ['id' => $data['individual_id']]
)->contain(['Organisations'])->first(); )->first();
$roleConditions = [ $roleConditions = [
'id' => $data['role_id'] 'id' => $data['role_id']
]; ];
@ -106,10 +106,9 @@ class AuthKeycloakBehavior extends Behavior
$roleConditions['name'] = Configure::read('keycloak.default_role_name'); $roleConditions['name'] = Configure::read('keycloak.default_role_name');
} }
$role = $this->_table->Roles->find()->where($roleConditions)->first(); $role = $this->_table->Roles->find()->where($roleConditions)->first();
$orgs = []; $org = $this->_table->Organisations->find()->where([
foreach ($individual['organisations'] as $org) { ['id' => $data['organisation_id']]
$orgs[] = $org['uuid']; ]);
}
$token = $this->getAdminAccessToken(); $token = $this->getAdminAccessToken();
$keyCloakUser = [ $keyCloakUser = [
'firstName' => $individual['first_name'], 'firstName' => $individual['first_name'],
@ -118,7 +117,7 @@ class AuthKeycloakBehavior extends Behavior
'email' => $individual['email'], 'email' => $individual['email'],
'attributes' => [ 'attributes' => [
'role_name' => empty($role['name']) ? Configure::read('keycloak.default_role_name') : $role['name'], 'role_name' => empty($role['name']) ? Configure::read('keycloak.default_role_name') : $role['name'],
'org_uuid' => empty($orgs[0]) ? '' : $orgs[0] 'org_uuid' => $orgs['uuid']
] ]
]; ];
$keycloakConfig = Configure::read('keycloak'); $keycloakConfig = Configure::read('keycloak');