Пример #1
0
 public function testGetAccessTokenWithExpiredAccessTokenAndRefreshToken()
 {
     $client = new Client();
     $mock = new MockPlugin();
     $mock->addResponse(new Response(200, null, json_encode(array("access_token" => "my_new_access_token_value", "token_type" => "Bearer"))));
     $client->addSubscriber($mock);
     $api = new Api("foo", $this->clientConfig[0], $this->storage, $client);
     $context = new Context("a_user", array("foo", "bar"));
     $accessToken = new AccessToken(array("client_config_id" => "foo", "user_id" => "a_user", "token_type" => "bearer", "access_token" => "my_token_value", "scope" => Scope::fromString("foo bar"), "issue_time" => time() - 4000, "expires_in" => 3600));
     $this->storage->storeAccessToken($accessToken);
     $refreshToken = new RefreshToken(array("client_config_id" => "foo", "user_id" => "a_user", "refresh_token" => "my_refresh_token_value", "scope" => Scope::fromString("foo bar"), "issue_time" => time() - 10000));
     $this->storage->storeRefreshToken($refreshToken);
     $accessToken = $api->getAccessToken($context);
     $this->assertEquals("my_new_access_token_value", $accessToken->getAccessToken());
     //$this->assertFalse($accessToken);
 }
Пример #2
0
 public function testGetAccessTokenWithExpiredAccessTokenAndRefreshToken()
 {
     $client = new Client();
     $mock = new MockPlugin();
     $mock->addResponse(new Response(200, null, json_encode(array('access_token' => 'my_new_access_token_value', 'token_type' => 'Bearer'))));
     $client->addSubscriber($mock);
     $guzzle3Client = new Guzzle3Client($client);
     $api = new Api('foo', $this->clientConfig[0], $this->storage, $guzzle3Client);
     $context = new Context('a_user', array('foo', 'bar'));
     $accessToken = new AccessToken(array('client_config_id' => 'foo', 'user_id' => 'a_user', 'token_type' => 'bearer', 'access_token' => 'my_token_value', 'scope' => Scope::fromString('foo bar'), 'issue_time' => time() - 4000, 'expires_in' => 3600));
     $this->storage->storeAccessToken($accessToken);
     $refreshToken = new RefreshToken(array('client_config_id' => 'foo', 'user_id' => 'a_user', 'refresh_token' => 'my_refresh_token_value', 'scope' => Scope::fromString('foo bar'), 'issue_time' => time() - 10000));
     $this->storage->storeRefreshToken($refreshToken);
     $accessToken = $api->getAccessToken($context);
     $this->assertEquals('my_new_access_token_value', $accessToken->getAccessToken());
     //$this->assertFalse($accessToken);
 }