|
@@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
use Symfony\Component\BrowserKit\Cookie;
|
|
use Symfony\Component\BrowserKit\Cookie;
|
|
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
|
|
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
|
|
|
|
+use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser;
|
|
use GuzzleHttp\Client as GuzzClient;
|
|
use GuzzleHttp\Client as GuzzClient;
|
|
use GuzzleHttp\Exception\ServerException as RequestException;
|
|
use GuzzleHttp\Exception\ServerException as RequestException;
|
|
use GuzzleHttp\Psr7;
|
|
use GuzzleHttp\Psr7;
|
|
@@ -53,35 +54,19 @@ class ImportONUCommand extends Command
|
|
|
|
|
|
$client_id = $input->getOption('client_id');
|
|
$client_id = $input->getOption('client_id');
|
|
$client_secret = $input->getOption('client_secret');
|
|
$client_secret = $input->getOption('client_secret');
|
|
-
|
|
|
|
|
|
+
|
|
$token = $this->getAccessToken($username, $password, $client_id, $client_secret);
|
|
$token = $this->getAccessToken($username, $password, $client_id, $client_secret);
|
|
-
|
|
|
|
|
|
+
|
|
$url = $base_url . $uri;
|
|
$url = $base_url . $uri;
|
|
-
|
|
|
|
- $parser = new \JsonCollectionParser\Parser();
|
|
|
|
$client = new GuzzClient();
|
|
$client = new GuzzClient();
|
|
- $parser->parse($file, function($data) use ($client, $url, $token) {
|
|
|
|
|
|
+ $parser = new \JsonCollectionParser\Parser();
|
|
|
|
+ $cookieJar = $this->getCookieJar($username, $token);
|
|
|
|
+
|
|
|
|
+ $parser->parse($file, function($data) use ($client, $url, $cookieJar, $token) {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
-
|
|
|
|
-// $cookie = $this->logIn($user, $token['access_token'], $token['refresh_token'], $token['expires_in']);
|
|
|
|
-// $cookieJar = CookieJar::fromArray([
|
|
|
|
-// $cookie->getName() => $cookie->getValue()
|
|
|
|
-// ], 'ftth.fd3.flowdat.com');
|
|
|
|
-//
|
|
|
|
-
|
|
|
|
-// $res = $client->request("POST", 'base.fd3.flowdat.com/oauth/v2/auth/login_check', [
|
|
|
|
-// 'auth' => [$user, $pass],
|
|
|
|
-// 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
|
|
|
|
-// 'body' => http_build_query([
|
|
|
|
-// '_username'=>$user,
|
|
|
|
-// '_password'=>$pass,
|
|
|
|
-// '_csrf_token'=>'XqptzqyIjxEvmrp8kPb6-1AuTNmxYwH5qfhVR6QNiKg'
|
|
|
|
-// ])
|
|
|
|
-// ]);
|
|
|
|
-//
|
|
|
|
$res = $client->request("POST", $url, [
|
|
$res = $client->request("POST", $url, [
|
|
-// 'cookies' => $cookieJar,
|
|
|
|
|
|
+ 'debug' => true,
|
|
|
|
+ 'cookies' => $cookieJar,
|
|
'headers' => ['Authorization' => "Bearer {$token['access_token']}"],
|
|
'headers' => ['Authorization' => "Bearer {$token['access_token']}"],
|
|
'body' => json_encode($data)
|
|
'body' => json_encode($data)
|
|
]);
|
|
]);
|
|
@@ -96,6 +81,17 @@ class ImportONUCommand extends Command
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Retorna un token OAuth
|
|
|
|
+ *
|
|
|
|
+ * @param string $username
|
|
|
|
+ * @param string $password
|
|
|
|
+ * @param string $client_id
|
|
|
|
+ * @param string $client_secret
|
|
|
|
+ * @param string $url
|
|
|
|
+ *
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
private function getAccessToken($username, $password, $client_id, $client_secret, $url = 'http://base.fd3.flowdat.com/oauth/v2/token')
|
|
private function getAccessToken($username, $password, $client_id, $client_secret, $url = 'http://base.fd3.flowdat.com/oauth/v2/token')
|
|
{
|
|
{
|
|
$body = ['grant_type' => 'password',
|
|
$body = ['grant_type' => 'password',
|
|
@@ -113,7 +109,16 @@ class ImportONUCommand extends Command
|
|
return json_decode($res->getBody(), true);
|
|
return json_decode($res->getBody(), true);
|
|
}
|
|
}
|
|
|
|
|
|
- private function logIn($username, $access_token, $refresh_token, $expires_in)
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Guardo en session al OAuthUser
|
|
|
|
+ * Retorno una cookie con la info de session
|
|
|
|
+ *
|
|
|
|
+ * @param string $username
|
|
|
|
+ * @param array $token
|
|
|
|
+ *
|
|
|
|
+ * @return CookieJar
|
|
|
|
+ */
|
|
|
|
+ private function getCookieJar($username, $token)
|
|
{
|
|
{
|
|
$session = new Session();
|
|
$session = new Session();
|
|
$session->setName('ftth_session');
|
|
$session->setName('ftth_session');
|
|
@@ -122,14 +127,19 @@ class ImportONUCommand extends Command
|
|
// the firewall context (defaults to the firewall name)
|
|
// the firewall context (defaults to the firewall name)
|
|
$firewall = 'secured_area';
|
|
$firewall = 'secured_area';
|
|
|
|
|
|
- $token = new OAuthToken($access_token, array('ROLE_USER'));
|
|
|
|
- $token->setAccessToken($access_token);
|
|
|
|
- $token->setRefreshToken($refresh_token);
|
|
|
|
- $token->setExpiresIn($expires_in);
|
|
|
|
- $session->set('_security_'.$firewall, serialize($token));
|
|
|
|
|
|
+ $OAuthToken = new OAuthToken($token['access_token'], array('ROLE_ADMIN', 'ROLE_USER'));
|
|
|
|
+ $OAuthToken->setRawToken($token);
|
|
|
|
+ $user = new OAuthUser($username);
|
|
|
|
+ $OAuthToken->setUser($user);
|
|
|
|
+
|
|
|
|
+ $session->set('_security_'.$firewall, $OAuthToken->serialize());
|
|
$session->save();
|
|
$session->save();
|
|
|
|
|
|
- return new Cookie($session->getName(), $session->getId());
|
|
|
|
|
|
+ $cookie = new Cookie($session->getName(), $session->getId());
|
|
|
|
+
|
|
|
|
+ return CookieJar::fromArray([
|
|
|
|
+ $cookie->getName() => $cookie->getValue(),
|
|
|
|
+ ], 'ftth.fd3.flowdat.com');
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|