예제 #1
0
 /**
  * @dataProvider providerReconstitute
  */
 public function testReconstitute($data)
 {
     /** @var RefreshToken $refreshToken */
     $refreshToken = RefreshToken::reconstitute($data);
     $this->assertEquals($data['token'], $refreshToken->getToken());
     $this->assertSame($data['owner'], $refreshToken->getOwner());
     $this->assertSame($data['client'], $refreshToken->getClient());
     if ($data['expiresAt'] instanceof DateTimeImmutable) {
         /** @var DateTimeImmutable $expiresAt */
         $expiresAt = $data['expiresAt'];
         $this->assertSame($expiresAt->getTimeStamp(), $refreshToken->getExpiresAt()->getTimestamp());
     } else {
         $this->assertNull($refreshToken->getExpiresAt());
     }
     $this->assertSame($data['scopes'], $refreshToken->getScopes());
 }
 /**
  * @return RefreshToken
  */
 private function getValidRefreshToken(TokenOwnerInterface $owner = null, array $scopes = null)
 {
     $validDate = (new \DateTimeImmutable())->add(new DateInterval('P1D'));
     $token = RefreshToken::reconstitute(['token' => 'azerty_refresh', 'owner' => $owner, 'client' => null, 'scopes' => $scopes ?? ['read'], 'expiresAt' => $validDate]);
     return $token;
 }
 /**
  * @dataProvider revocationProvider
  */
 public function testReturn503IfCannotRevoke($tokenType)
 {
     $request = $this->createMock(ServerRequestInterface::class);
     $request->expects($this->once())->method('getParsedBody')->willReturn(['token' => 'abc', 'token_type_hint' => $tokenType]);
     $clientService = $this->createMock(ClientService::class);
     $grant = $this->createMock(GrantInterface::class);
     $accessTokenService = $this->createMock(AccessTokenService::class);
     $refreshTokenService = $this->createMock(RefreshTokenService::class);
     $authorizationServer = new AuthorizationServer($clientService, [$grant], $accessTokenService, $refreshTokenService);
     if ($tokenType === 'access_token') {
         $token = AccessToken::reconstitute(['token' => 'abc', 'owner' => null, 'client' => null, 'scopes' => [], 'expiresAt' => new \DateTimeImmutable()]);
         $accessTokenService->expects($this->once())->method('getToken')->with('abc')->will($this->returnValue($token));
         $accessTokenService->expects($this->once())->method('deleteToken')->with($token)->will($this->throwException(new \RuntimeException()));
     } elseif ($tokenType === 'refresh_token') {
         $token = RefreshToken::reconstitute(['token' => 'abc', 'owner' => null, 'client' => null, 'scopes' => [], 'expiresAt' => new \DateTimeImmutable()]);
         $refreshTokenService->expects($this->once())->method('getToken')->with('abc')->will($this->returnValue($token));
         $refreshTokenService->expects($this->once())->method('deleteToken')->with($token)->will($this->throwException(new \RuntimeException()));
     }
     $response = $authorizationServer->handleRevocationRequest($request);
     $this->assertInstanceOf(ResponseInterface::class, $response);
     $this->assertEquals(503, $response->getStatusCode());
 }