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()); }
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'))); }
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; }
public function testEmptyStringFromString() { $s = Scope::fromString(''); $this->assertTrue($s->isEmpty()); }