diff --git a/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php b/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php index a1d64061..ec4f4f66 100644 --- a/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php +++ b/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php @@ -69,7 +69,7 @@ private function getUserIdentity(string $userId): UserIdentity $email = $this->getPropertyValue($user, UserRdf::PROPERTY_MAIL); - $locale = $this->getPropertyValue($user, UserRdf::PROPERTY_DEFLG); + $locale = $this->detectLocale($user); return new UserIdentity($login, trim($fullName), $email, $firstName, $lastName, null, $locale); } @@ -79,6 +79,18 @@ private function getPropertyValue(User $user, string $propertyName): ?string return $user->getPropertyValues($propertyName)[0] ?? null; } + private function detectLocale(User $user): ?string + { + if ( + !empty($this->getPropertyValue($user, UserRdf::PROPERTY_LOGIN)) + || !defined('DEFAULT_ANONYMOUS_INTERFACE_LANG') + ) { + return $this->getPropertyValue($user, UserRdf::PROPERTY_DEFLG); + } else { + return DEFAULT_ANONYMOUS_INTERFACE_LANG; + } + } + private function getUserService(): UserService { return $this->getServiceLocator()->get(UserService::SERVICE_ID); diff --git a/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php b/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php index fab18695..a08a77ac 100644 --- a/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php +++ b/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php @@ -106,7 +106,13 @@ public function testAnonymousOrGuestUser(): void new UserIdentity( 'userId#123456', '', - '' + '', + null, + null, + null, + defined('DEFAULT_ANONYMOUS_INTERFACE_LANG') + ? DEFAULT_ANONYMOUS_INTERFACE_LANG + : DEFAULT_LANG ) ), $this->subject->authenticate($registration, 'userId#123456') @@ -132,6 +138,7 @@ private function expectUser( [UserRdf::PROPERTY_FIRSTNAME], [UserRdf::PROPERTY_LASTNAME], [UserRdf::PROPERTY_MAIL], + [UserRdf::PROPERTY_LOGIN], [UserRdf::PROPERTY_DEFLG] ) ->willReturnOnConsecutiveCalls( @@ -139,7 +146,8 @@ private function expectUser( [$firstName], [$lastName], [$email], - [$locale], + [$login], + [$locale] ); $this->userService