Ejemplo n.º 1
0
 public function testUpdatesTokenFieldsOnFetchMissingRefreshToken()
 {
     $testConfig = $this->fetchAuthTokenMinimal;
     $testConfig['refresh_token'] = 'a_refresh_token';
     $wanted_updates = ['expires_at' => '1', 'expires_in' => '57', 'issued_at' => '2', 'access_token' => 'an_access_token', 'id_token' => 'an_id_token'];
     $json = json_encode($wanted_updates);
     $httpHandler = getHandler([buildResponse(200, [], Psr7\stream_for($json))]);
     $o = new OAuth2($testConfig);
     $this->assertNull($o->getExpiresAt());
     $this->assertNull($o->getExpiresIn());
     $this->assertNull($o->getIssuedAt());
     $this->assertNull($o->getAccessToken());
     $this->assertNull($o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
     $tokens = $o->fetchAuthToken($httpHandler);
     $this->assertEquals(1, $o->getExpiresAt());
     $this->assertEquals(57, $o->getExpiresIn());
     $this->assertEquals(2, $o->getIssuedAt());
     $this->assertEquals('an_access_token', $o->getAccessToken());
     $this->assertEquals('an_id_token', $o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
 }
 public function testUpdatesTokenFieldsOnFetch()
 {
     $testConfig = $this->fetchAuthTokenMinimal;
     $wanted_updates = ['expires_at' => '1', 'expires_in' => '57', 'issued_at' => '2', 'access_token' => 'an_access_token', 'id_token' => 'an_id_token', 'refresh_token' => 'a_refresh_token'];
     $json = json_encode($wanted_updates);
     $client = new Client();
     $plugin = new Mock();
     $plugin->addResponse(new Response(200, [], Stream::factory($json)));
     $client->getEmitter()->attach($plugin);
     $o = new OAuth2($testConfig);
     $this->assertNull($o->getExpiresAt());
     $this->assertNull($o->getExpiresIn());
     $this->assertNull($o->getIssuedAt());
     $this->assertNull($o->getAccessToken());
     $this->assertNull($o->getIdToken());
     $this->assertNull($o->getRefreshToken());
     $tokens = $o->fetchAuthToken($client);
     $this->assertEquals(1, $o->getExpiresAt());
     $this->assertEquals(57, $o->getExpiresIn());
     $this->assertEquals(2, $o->getIssuedAt());
     $this->assertEquals('an_access_token', $o->getAccessToken());
     $this->assertEquals('an_id_token', $o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
 }