Esempio 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);
     $state = new State(array("state" => "my_state", "client_config_id" => "foo", "issue_time" => time() - 100, "user_id" => "my_user_id", "scope" => Scope::fromString("foo bar")));
     $this->storage->storeState($state);
     $callback = new Callback("foo", $this->clientConfig[0], $this->storage, $client);
     $tokenResponse = $callback->handleCallback(array("state" => "my_state", "code" => "my_code"));
     $this->assertEquals("my_access_token", $tokenResponse->getAccessToken());
 }
Esempio n. 2
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);
     $state = new State(array('state' => 'my_state', 'client_config_id' => 'foo', 'issue_time' => time() - 100, 'user_id' => 'my_user_id', 'scope' => Scope::fromString('foo bar')));
     $this->storage->storeState($state);
     $guzzle3Client = new Guzzle3Client($client);
     $callback = new Callback('foo', $this->clientConfig[0], $this->storage, $guzzle3Client);
     $tokenResponse = $callback->handleCallback(array('state' => 'my_state', 'code' => 'my_code'));
     $this->assertEquals('my_access_token', $tokenResponse->getAccessToken());
 }
Esempio n. 3
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);
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 public function setScope($scope)
 {
     $scope = Scope::fromString($scope);
     if ($scope->isEmpty()) {
         throw new TokenResponseException("scope must be non empty");
     }
     $this->scope = $scope;
 }
Esempio n. 6
0
 public function equals(Scope $that)
 {
     $thisScope = $this->toArray();
     $thatScope = $that->toArray();
     foreach ($thisScope as $s) {
         if (!in_array($s, $thatScope)) {
             return false;
         }
     }
     foreach ($thatScope as $s) {
         if (!in_array($s, $thisScope)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 7
0
 public function getState($clientConfigId, $state)
 {
     $stmt = $this->db->prepare(sprintf('SELECT * FROM %s WHERE client_config_id = :client_config_id AND state = :state', $this->prefix . 'states'));
     $stmt->bindValue(':client_config_id', $clientConfigId, PDO::PARAM_STR);
     $stmt->bindValue(':state', $state, PDO::PARAM_STR);
     $stmt->execute();
     $result = $stmt->fetch(PDO::FETCH_ASSOC);
     if (false !== $result) {
         $result['scope'] = Scope::fromString($result['scope']);
         return new State($result);
     }
     return false;
 }
Esempio n. 8
0
 public function getState($clientConfigId, $state)
 {
     $collection = $this->mongo->selectCollection($this->db, 'state');
     $result = $collection->findOne(array('client_config_id' => $clientConfigId, 'state' => $state));
     if (null !== $result) {
         $result['scope'] = Scope::fromString($result['scope']);
         return new fkooman\OAuth\Client\State($result);
     }
     return false;
 }
 public function testAllowCommaSeparatedScope()
 {
     $client = new Client();
     $mock = new MockPlugin();
     $mock->addResponse(new Response(200, null, $this->tokenResponse[4]));
     $client->addSubscriber($mock);
     $history = new HistoryPlugin();
     $history->setLimit(5);
     $client->addSubscriber($history);
     $guzzle3Client = new Guzzle3Client($client);
     $tokenRequest = new TokenRequest($guzzle3Client, $this->clientConfig[4]);
     $tokenResponse = $tokenRequest->withAuthorizationCode('12345');
     $this->assertTrue($tokenResponse->getScope()->equals(Scope::fromString('foo bar')));
 }
Esempio n. 10
0
 public function testSerialize()
 {
     $s = new Scope(array("foo", "bar", "baz"));
     $t = new Scope($s->toArray());
     $this->assertTrue($t->equals($s));
 }
 /**
  * OPTIONAL.  A space-separated list of strings representing the
  * scopes associated with this token, in the format described in
  * Section 3.3 of OAuth 2.0 [RFC6749].
  *
  * @return fkooman\OAuth\Common\Scope
  */
 public function getScope()
 {
     $scopeValue = $this->getKeyValue('scope');
     if (false === $scopeValue) {
         return new Scope();
     }
     return Scope::fromString($scopeValue);
 }
 /**
  * OPTIONAL.  A space-separated list of strings representing the
  * scopes associated with this token, in the format described in
  * Section 3.3 of OAuth 2.0 [RFC6749].
  *
  * @return fkooman\OAuth\Common\Scope
  */
 public function getScope()
 {
     if (null === $this->getKeyValue('scope')) {
         return new Scope();
     }
     return Scope::fromString($this->getKeyValue('scope'));
 }