public function testFailAuthenticationOnExpiredToken() { $token = new AccessToken(); $owner = $this->getMock(TokenOwnerInterface::class); $token->setOwner($owner); $this->resourceServer->expects($this->atLeastOnce())->method('getAccessToken')->with($this->isInstanceOf(PsrServerRequestInterface::class))->will($this->throwException(new OAuth2Exception('Expired token', 123))); $this->setExpectedException(OAuth2Exception::class, 'Expired token', 123); $this->authenticationService->getIdentity(); }
public function testReadOwnerFromAccessToken() { $token = new AccessToken(); $owner = $this->getMock(TokenOwnerInterface::class); $token->setOwner($owner); $this->resourceServer->expects($this->atLeastOnce())->method('getAccessToken')->with($this->isInstanceOf(ServerRequestInterface::class))->will($this->returnValue($token)); $this->assertFalse($this->storage->isEmpty()); $this->assertSame($owner, $this->storage->read()); }
public function generateAccessToken(TokenOwnerInterface $user) { $token = new AccessToken(); $token->setOwner($user); $token->setToken(substr(md5(rand()), 0, 7)); $expiresAt = new DateTime(); $token->setExpiresAt($expiresAt->modify('+1 hour')); $this->entityManager->persist($token); $this->entityManager->flush(); return $token->getToken(); }
public function testCanCreateTokenResponse() { $request = $this->getMock(ServerRequestInterface::class); $client = new Client(); $owner = $this->getMock(TokenOwnerInterface::class); $owner->expects($this->once())->method('getTokenOwnerId')->will($this->returnValue(1)); $token = new AccessToken(); $token->setToken('azerty'); $token->setOwner($owner); $token->setExpiresAt((new DateTime())->add(new DateInterval('PT1H'))); $this->tokenService->expects($this->once())->method('createToken')->will($this->returnValue($token)); $response = $this->grant->createTokenResponse($request, $client, $owner); $body = json_decode($response->getBody(), true); $this->assertEquals('azerty', $body['access_token']); $this->assertEquals('Bearer', $body['token_type']); $this->assertEquals(3600, $body['expires_in']); $this->assertEquals(1, $body['owner_id']); }
public function testGettersAndSetters() { $owner = $this->getMock(TokenOwnerInterface::class); $client = new Client(); $expiresAt = new DateTime(); $accessToken = new AccessToken(); $accessToken->setToken('token'); $accessToken->setScopes(['scope1', 'scope2']); $accessToken->setClient($client); $accessToken->setExpiresAt($expiresAt); $accessToken->setOwner($owner); $this->assertEquals('token', $accessToken->getToken()); $this->assertCount(2, $accessToken->getScopes()); $this->assertTrue($accessToken->matchScopes('scope1')); $this->assertFalse($accessToken->matchScopes('scope3')); $this->assertSame($client, $accessToken->getClient()); $this->assertEquals($expiresAt, $accessToken->getExpiresAt()); $this->assertSame($owner, $accessToken->getOwner()); }