Exemplo n.º 1
0
 public function testXYZ()
 {
     $client = new Client();
     $mock = new MockPlugin();
     $mock->addResponse(new Response(200, null, json_encode(array("access_token" => "my_access_token", "token_type" => "BeArEr", "refresh_token" => "why_not_a_refresh_token"))));
     $client->addSubscriber($mock);
     $mockStorage = new MockStorage();
     $state = new State(array("state" => "my_state", "client_config_id" => "foo", "issue_time" => time() - 100, "user_id" => "my_user_id", "scope" => new Scope("foo bar")));
     $mockStorage->storeState($state);
     $callback = new Callback("foo", $this->clientConfig[0], $mockStorage, $client);
     $tokenResponse = $callback->handleCallback(array("state" => "my_state", "code" => "my_code"));
     $this->assertEquals("my_access_token", $tokenResponse->getAccessToken());
 }
Exemplo n.º 2
0
 public function testGetAccessTokenWithExpiredAccessTokenAndRefreshToken()
 {
     $mockStorage = new MockStorage();
     $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], $mockStorage, $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));
     $mockStorage->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));
     $mockStorage->storeRefreshToken($refreshToken);
     $accessToken = $api->getAccessToken($context);
     $this->assertEquals("my_new_access_token_value", $accessToken->getAccessToken());
     //$this->assertFalse($accessToken);
 }