aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/LTI13a/UserAuthenticator.php
blob: 125a60856867efd8fdf065ea49f0ed827a41ecd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

namespace Studip\LTI13a;

use OAT\Library\Lti1p3Core\Security\User\UserAuthenticatorInterface;
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;
use OAT\Library\Lti1p3Core\Security\User\Result\UserAuthenticationResultInterface;
use OAT\Library\Lti1p3Core\Security\User\Result\UserAuthenticationResult;
use Psr\Log\LoggerInterface;

class UserAuthenticator implements UserAuthenticatorInterface
{
    protected $logger = null;

    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    #[\Override]
    public function authenticate(RegistrationInterface $registration, string $loginHint): UserAuthenticationResultInterface
    {
        $user = \User::find($loginHint);

        $identity = null;
        $tool = null;
        if ($registration instanceof Registration) {
            $tool = $registration->getLtiTool();
        } else {
            $tool = \LtiTool::find($registration->getIdentifier());
        }
        if ($user && $tool) {
            $identity = new Identity($user, $tool);
        }

        return new UserAuthenticationResult($user instanceof \User, $identity);
    }
}