|
@@ -3,6 +3,7 @@
|
|
namespace Base\OAuthServerBundle\Command;
|
|
namespace Base\OAuthServerBundle\Command;
|
|
|
|
|
|
use \Base\OAuthServerBundle\Entity\OAuthClient;
|
|
use \Base\OAuthServerBundle\Entity\OAuthClient;
|
|
|
|
+use \FOS\OAuthServerBundle\Entity\ClientManager;
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
@@ -19,10 +20,22 @@ class OAuthClientCreateCommand extends ContainerAwareCommand
|
|
->setHelp('This command allows you to create an OAuth client')
|
|
->setHelp('This command allows you to create an OAuth client')
|
|
->addOption(
|
|
->addOption(
|
|
'redirect_uri',
|
|
'redirect_uri',
|
|
- 'r',
|
|
|
|
|
|
+ null,
|
|
InputOption::VALUE_REQUIRED,
|
|
InputOption::VALUE_REQUIRED,
|
|
'OAuth Redirect URI',
|
|
'OAuth Redirect URI',
|
|
'http://127.0.0.1/ftth/app_dev.php/login_check'
|
|
'http://127.0.0.1/ftth/app_dev.php/login_check'
|
|
|
|
+ )
|
|
|
|
+ ->addOption(
|
|
|
|
+ 'client_id',
|
|
|
|
+ null,
|
|
|
|
+ InputOption::VALUE_OPTIONAL,
|
|
|
|
+ 'OAuth Client random Id'
|
|
|
|
+ )
|
|
|
|
+ ->addOption(
|
|
|
|
+ 'client_secret',
|
|
|
|
+ null,
|
|
|
|
+ InputOption::VALUE_OPTIONAL,
|
|
|
|
+ 'OAuth Client random Secret'
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -32,18 +45,44 @@ class OAuthClientCreateCommand extends ContainerAwareCommand
|
|
*/
|
|
*/
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
{
|
|
|
|
+ $redirectUri = $input->getOption('redirect_uri');
|
|
|
|
+ $random = $input->getOption('client_id');
|
|
|
|
+ $secret = $input->getOption('client_secret');
|
|
|
|
+
|
|
|
|
+ $client = $this->createClient($redirectUri, $random, $secret);
|
|
|
|
+
|
|
|
|
+ $output->writeln('OAuth client successfully generated!');
|
|
|
|
+ $output->writeln('<info>client_id:</info> '.$client->getPublicId());
|
|
|
|
+ $output->writeln('<info>client_secret:</info> '.$client->getSecret());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param string $redirectUri
|
|
|
|
+ * @param string $random
|
|
|
|
+ * @param string $secret
|
|
|
|
+ *
|
|
|
|
+ * @return OAuthClient
|
|
|
|
+ */
|
|
|
|
+ protected function createClient($redirectUri, $random = null, $secret = null)
|
|
|
|
+ {
|
|
|
|
+ /* @var $clientManager ClientManager */
|
|
$clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
|
|
$clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
|
|
|
|
|
|
|
|
+ /* @var $client OAuthClient */
|
|
$client = $clientManager->createClient();
|
|
$client = $clientManager->createClient();
|
|
|
|
+ if ($random) {
|
|
|
|
+ $client->setRandomId($random);
|
|
|
|
+ }
|
|
|
|
+ if ($secret) {
|
|
|
|
+ $client->setSecret($secret);
|
|
|
|
+ }
|
|
$client->setRedirectUris(array(
|
|
$client->setRedirectUris(array(
|
|
- $input->getOption('redirect_uri'),
|
|
|
|
|
|
+ $redirectUri,
|
|
));
|
|
));
|
|
$client->setAllowedGrantTypes(array_keys(OAuthClient::getGrantTypesChoices()));
|
|
$client->setAllowedGrantTypes(array_keys(OAuthClient::getGrantTypesChoices()));
|
|
$clientManager->updateClient($client);
|
|
$clientManager->updateClient($client);
|
|
|
|
|
|
- $output->writeln('OAuth client successfully generated!');
|
|
|
|
- $output->writeln('<info>client_id:</info> '.$client->getPublicId());
|
|
|
|
- $output->writeln('<info>client_secret:</info> '.$client->getSecret());
|
|
|
|
|
|
+ return $client;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|