Example #1
0
 public function testAuthenticate()
 {
     $client = Client::reconstitute(['id' => '325e4ffc-ff89-4558-971a-6c6a4c13e718', 'name' => 'name', 'secret' => '$2y$10$LHAy5E0b1Fie9NpV6KeOWeAmVdA6UnaXP82TNoMGiVl0Sy/E6PUs6', 'redirectUris' => []]);
     $this->assertFalse($client->authenticate('azerty'));
     $this->assertTrue($client->authenticate('17ef7d94a9172d31c6336424651c861fad9c891e'));
     $this->assertFalse($client->authenticate($client->getSecret()));
 }
 public function testCanGetClient()
 {
     $client = Client::reconstitute(['id' => 'client_id', 'name' => 'name', 'secret' => '', 'redirectUris' => []]);
     $this->clientRepository->expects($this->once())->method('findById')->with('client_id')->will($this->returnValue($client));
     $this->assertSame($client, $this->clientService->getClient('client_id'));
 }
 /**
  * @dataProvider hasRefreshGrant
  */
 public function testCanCreateTokenResponse($hasRefreshGrant)
 {
     $request = $this->createMock(ServerRequestInterface::class);
     $request->expects($this->once())->method('getParsedBody')->willReturn(['code' => '123', 'client_id' => 'client_123']);
     $client = Client::reconstitute(['id' => 'client_123', 'name' => 'name', 'secret' => '', 'redirectUris' => []]);
     $token = $this->getValidAuthorizationCode(null, null, $client);
     $this->authorizationCodeService->expects($this->once())->method('getToken')->with('123')->will($this->returnValue($token));
     $owner = $this->createMock(TokenOwnerInterface::class);
     $owner->expects($this->once())->method('getTokenOwnerId')->will($this->returnValue(1));
     $accessToken = $this->getValidAccessToken($owner);
     $this->accessTokenService->expects($this->once())->method('createToken')->will($this->returnValue($accessToken));
     if ($hasRefreshGrant) {
         $refreshToken = $this->getValidRefreshToken();
         $this->refreshTokenService->expects($this->once())->method('createToken')->will($this->returnValue($refreshToken));
     }
     $authorizationServer = $this->createMock(AuthorizationServer::class);
     $authorizationServer->expects($this->once())->method('hasGrant')->with(RefreshTokenGrant::GRANT_TYPE)->will($this->returnValue($hasRefreshGrant));
     $this->grant = new AuthorizationGrant($this->authorizationCodeService, $this->accessTokenService, $this->refreshTokenService);
     $this->grant->setAuthorizationServer($authorizationServer);
     $response = $this->grant->createTokenResponse($request, $client, $owner);
     $body = json_decode($response->getBody(), true);
     $this->assertEquals('azerty_access', $body['access_token']);
     $this->assertEquals('Bearer', $body['token_type']);
     $this->assertEquals(3600, $body['expires_in']);
     $this->assertEquals('read', $body['scope']);
     $this->assertEquals(1, $body['owner_id']);
     if ($hasRefreshGrant) {
         $this->assertEquals('azerty_refresh', $body['refresh_token']);
     }
 }