示例#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);
     $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());
 }
示例#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);
 }
 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')));
 }
示例#4
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;
 }
 public function setScope($scope)
 {
     $scope = Scope::fromString($scope);
     if ($scope->isEmpty()) {
         throw new TokenResponseException('scope must be non empty');
     }
     $this->scope = $scope;
 }
示例#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;
 }
示例#7
0
 public function testSerialize()
 {
     $s = new Scope(array('foo', 'bar', 'baz'));
     $t = new Scope($s->toArray());
     $this->assertTrue($t->equals($s));
 }