Total Complexity | 5 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
16 | final class QueryParameter implements AuthenticationMethodInterface |
||
17 | { |
||
18 | private const PARAMETER_NAME = 'access-token'; |
||
19 | /** |
||
20 | * @var string the parameter name for passing the access token |
||
21 | */ |
||
22 | private string $parameterName = self::PARAMETER_NAME; |
||
23 | |||
24 | private IdentityRepositoryInterface $identityRepository; |
||
25 | |||
26 | 8 | public function __construct(IdentityRepositoryInterface $identityRepository) |
|
27 | { |
||
28 | 8 | $this->identityRepository = $identityRepository; |
|
29 | 8 | } |
|
30 | |||
31 | 6 | public function authenticate(ServerRequestInterface $request): ?IdentityInterface |
|
32 | { |
||
33 | 6 | $accessToken = $request->getQueryParams()[$this->parameterName] ?? null; |
|
34 | 6 | if (is_string($accessToken)) { |
|
35 | 5 | return $this->identityRepository->findIdentityByToken($accessToken, get_class($this)); |
|
36 | } |
||
37 | |||
38 | 3 | return null; |
|
39 | } |
||
40 | |||
41 | 2 | public function challenge(ResponseInterface $response): ResponseInterface |
|
42 | { |
||
43 | 2 | return $response; |
|
44 | } |
||
45 | |||
46 | 1 | public function withParameterName(string $name): self |
|
51 | } |
||
52 | } |
||
53 |