/**
  * {@inheritDoc}
  */
 public function read()
 {
     if (!$this->request) {
         return null;
     }
     $accessToken = $this->resourceServer->getAccessToken($this->request);
     return $accessToken ? $accessToken->getOwner() : null;
 }
 /**
  * @dataProvider requestProvider
  */
 public function testCanValidateAccessToResource($expiredToken, $tokenScope, $desiredScope, $match)
 {
     $request = $this->createMock(ServerRequestInterface::class);
     $request->expects($this->once())->method('hasHeader')->with('Authorization')->will($this->returnValue(true));
     $request->expects($this->once())->method('getHeaderLine')->will($this->returnValue('Bearer token'));
     if ($expiredToken) {
         $accessToken = AccessToken::createNewAccessToken(-3600, null, null, $tokenScope);
     } else {
         $accessToken = AccessToken::createNewAccessToken(3600, null, null, $tokenScope);
     }
     $this->tokenService->expects($this->once())->method('getToken')->with('token')->will($this->returnValue($accessToken));
     if (!$match || $expiredToken) {
         $this->expectException(InvalidAccessTokenException::class);
     }
     $tokenResult = $this->resourceServer->getAccessToken($request, $desiredScope);
     $this->assertInstanceOf(AccessToken::class, $tokenResult);
 }
 /**
  * @dataProvider requestProvider
  */
 public function testCanValidateAccessToResource($expiredToken, $tokenScope, $desiredScope, $match)
 {
     $request = $this->getMock(ServerRequestInterface::class);
     $request->expects($this->once())->method('hasHeader')->with('Authorization')->will($this->returnValue(true));
     $request->expects($this->once())->method('getHeaderLine')->will($this->returnValue('Bearer token'));
     $accessToken = new AccessToken();
     $date = new DateTime();
     if ($expiredToken) {
         $date->sub(new DateInterval('P1D'));
     } else {
         $date->add(new DateInterval('P1D'));
     }
     $accessToken->setExpiresAt($date);
     $accessToken->setScopes($tokenScope);
     $this->tokenService->expects($this->once())->method('getToken')->with('token')->will($this->returnValue($accessToken));
     if (!$match || $expiredToken) {
         $this->setExpectedException(InvalidAccessTokenException::class);
     }
     $tokenResult = $this->resourceServer->getAccessToken($request, $desiredScope);
     $this->assertInstanceOf(AccessToken::class, $tokenResult);
 }