diff --git a/appinfo/info.xml b/appinfo/info.xml index 3997e0ee5a3094bb8918dbbf3522d04ada6a7c69..64b13ea76f2fbef79e05f241e71198412c8ed12e 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ - 10.0.1 + 10.0.2 agpl Murena SAS EcloudAccounts diff --git a/lib/Service/SSOService.php b/lib/Service/SSOService.php index 05e591f521c34b06863db956a8cc0d9f385cf98b..61882dc23270f1a612481532f5a9a43e6cb9edd0 100644 --- a/lib/Service/SSOService.php +++ b/lib/Service/SSOService.php @@ -174,12 +174,29 @@ class SSOService { if (empty($users) || !is_array($users) || !isset($users[0])) { throw new SSOAdminAPIException('Error: no user found for search with url: ' . $url); } - $this->currentUserId = $users[0]['id']; - $this->currentUserName = $this->sanitizeUserName($users[0]['username']); + + $ssoUserId = ''; + $ssoUserName = ''; $username = $this->sanitizeUserName($username); - if ($username !== $this->currentUserName) { + + foreach($users as $ssoUser) { + if (!isset($ssoUser['username']) || !isset($ssoUser['id'])) { + continue; + } + + $ssoUserName = $ssoUser['username']; + if ($ssoUserName === $username) { + $ssoUserId = $ssoUser['id']; + break; + } + } + + if (empty($ssoUserId) || empty($ssoUserName)) { throw new SSOAdminAPIException('Error: retrieved wrong user info (' . $this->currentUserName . ') from SSO service for ' . $username); } + + $this->currentUserId = $ssoUserId; + $this->currentUserName = $ssoUserName; } private function getAdminAccessToken() : void { @@ -250,7 +267,11 @@ class SSOService { return $answer; } - private function sanitizeUserName(string $username): string { + private function sanitizeUserName(?string $username): ?string { + if (!isset($username) || is_null($username) || empty($username)) { + return null; + } + $username = strtolower($username); if (str_contains($username, "@" . $this->mainDomain) || str_contains($username, "@" . $this->legacyDomain)) {