1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Bundle\Service; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\Authorization; |
17
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\RedirectToLoginPageException; |
18
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\UserAccountDiscovery\UserAccountDiscovery; |
19
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccount; |
20
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
21
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
22
|
|
|
|
23
|
|
|
final class SymfonyUserDiscovery implements UserAccountDiscovery |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var TokenStorageInterface |
27
|
|
|
*/ |
28
|
|
|
private $tokenStorage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var AuthorizationCheckerInterface |
32
|
|
|
*/ |
33
|
|
|
private $authorizationChecker; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* SymfonyUserDiscovery constructor. |
37
|
|
|
* |
38
|
|
|
* @param TokenStorageInterface $tokenStorage |
39
|
|
|
* @param AuthorizationCheckerInterface $authorizationChecker |
40
|
|
|
*/ |
41
|
|
|
public function __construct(TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker) |
42
|
|
|
{ |
43
|
|
|
$this->tokenStorage = $tokenStorage; |
44
|
|
|
$this->authorizationChecker = $authorizationChecker; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function find(Authorization $authorization, ?bool &$isFullyAuthenticated = null): ?UserAccount |
51
|
|
|
{ |
52
|
|
|
if (null !== $token = $this->tokenStorage->getToken()) { |
53
|
|
|
$userAccount = $token->getUser(); |
54
|
|
|
if ($userAccount instanceof UserAccount) { |
55
|
|
|
$isFullyAuthenticated = $this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY'); |
56
|
|
|
|
57
|
|
|
return $userAccount; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function check(Authorization $authorization) |
68
|
|
|
{ |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|