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