Skip to content

Commit

Permalink
fix: Anonymous user type does not work correctly for LTI
Browse files Browse the repository at this point in the history
  • Loading branch information
Makar Sichevoi committed Apr 22, 2024
1 parent 147b66c commit 891b6bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
11 changes: 6 additions & 5 deletions models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public function authenticate(
string $loginHint
): UserAuthenticationResultInterface {
try {
if ($loginHint === '') {
return new UserAuthenticationResult(true);
}

return new UserAuthenticationResult(true, $this->getUserIdentity($loginHint));
} catch (Throwable $exception) {
return new UserAuthenticationResult(false);
Expand All @@ -54,8 +50,13 @@ public function authenticate(
/**
* @throws ErrorException
*/
private function getUserIdentity(string $userId): UserIdentity
private function getUserIdentity(string $userId): ?UserIdentity
{
// anonymous user without login data
if ($userId === '') {
return null;
}

$user = $this->getUserService()
->getUser($userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Lti1p3UserAuthenticatorTest extends TestCase
{
use ServiceManagerMockTrait;

const LOGINHINT = 'userId#123456';

/** @var Lti1p3UserAuthenticator */
private $subject;

Expand Down Expand Up @@ -85,7 +87,7 @@ public function testAuthenticateUser(): void
'en-US'
)
),
$this->subject->authenticate($registration, 'userId#123456')
$this->subject->authenticate($registration, self::LOGINHINT)
);
}

Expand All @@ -104,12 +106,32 @@ public function testAnonymousOrGuestUser(): void
new UserAuthenticationResult(
true,
new UserIdentity(
'userId#123456',
self::LOGINHINT,
'',
''
)
),
$this->subject->authenticate($registration, 'userId#123456')
$this->subject->authenticate($registration, self::LOGINHINT)
);
}

public function testAnonymousWithoutLoginHintData(): void
{
$this->expectAnonymousUser(
[
'role'
]
);

/** @var RegistrationInterface|MockObject $registration */
$registration = $this->createMock(RegistrationInterface::class);

$this->assertEquals(
new UserAuthenticationResult(
true,
null
),
$this->subject->authenticate($registration, '')
);
}

Expand Down

0 comments on commit 891b6bd

Please sign in to comment.