|
@@ -15,28 +15,18 @@ class OAuthClientCreateCommand extends ContainerAwareCommand
|
|
protected function configure()
|
|
protected function configure()
|
|
{
|
|
{
|
|
$this
|
|
$this
|
|
- ->setName('oauth:client:create')
|
|
|
|
- ->setDescription('Create OAuht client')
|
|
|
|
- ->setHelp('This command allows you to create an OAuth client')
|
|
|
|
- ->addOption(
|
|
|
|
- 'redirect_uri',
|
|
|
|
- null,
|
|
|
|
- InputOption::VALUE_REQUIRED,
|
|
|
|
- 'OAuth Redirect URI',
|
|
|
|
- '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'
|
|
|
|
- );
|
|
|
|
|
|
+ ->setName('oauth:client:create')
|
|
|
|
+ ->setDescription('Create OAuht client')
|
|
|
|
+ ->setHelp('This command allows you to create an OAuth client')
|
|
|
|
+ ->addOption(
|
|
|
|
+ 'redirect_uri', null, InputOption::VALUE_REQUIRED, 'OAuth Redirect URI', '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'
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -48,14 +38,14 @@ class OAuthClientCreateCommand extends ContainerAwareCommand
|
|
$redirectUri = $input->getOption('redirect_uri');
|
|
$redirectUri = $input->getOption('redirect_uri');
|
|
$random = $input->getOption('client_id');
|
|
$random = $input->getOption('client_id');
|
|
$secret = $input->getOption('client_secret');
|
|
$secret = $input->getOption('client_secret');
|
|
-
|
|
|
|
|
|
+
|
|
$client = $this->createClient($redirectUri, $random, $secret);
|
|
$client = $this->createClient($redirectUri, $random, $secret);
|
|
-
|
|
|
|
|
|
+
|
|
$output->writeln('#OAuth client successfully generated!');
|
|
$output->writeln('#OAuth client successfully generated!');
|
|
- $output->writeln('OAUTH_CLIENT_ID='.$client->getPublicId());
|
|
|
|
- $output->writeln('OAUTH_CLIENT_SECRET='.$client->getSecret());
|
|
|
|
|
|
+ $output->writeln('<info>OAUTH_CLIENT_ID</info>=' . $client->getPublicId());
|
|
|
|
+ $output->writeln('<info>OAUTH_CLIENT_SECRET</info>=' . $client->getSecret());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param string $redirectUri
|
|
* @param string $redirectUri
|
|
* @param string $random
|
|
* @param string $random
|
|
@@ -67,21 +57,25 @@ class OAuthClientCreateCommand extends ContainerAwareCommand
|
|
{
|
|
{
|
|
/* @var $clientManager ClientManager */
|
|
/* @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();
|
|
|
|
- if ($random) {
|
|
|
|
- $client->setRandomId($random);
|
|
|
|
- }
|
|
|
|
- if ($secret) {
|
|
|
|
- $client->setSecret($secret);
|
|
|
|
|
|
+
|
|
|
|
+ $em = $this->getContainer()->get('doctrine')->getEntityManager();
|
|
|
|
+ $client = $em->getRepository('BaseOAuthServerBundle:OAuthClient')->findOneByRedirectUri($redirectUri);
|
|
|
|
+ if (!$client) {
|
|
|
|
+ /* @var $client OAuthClient */
|
|
|
|
+ $client = $clientManager->createClient();
|
|
|
|
+ if ($random) {
|
|
|
|
+ $client->setRandomId($random);
|
|
|
|
+ }
|
|
|
|
+ if ($secret) {
|
|
|
|
+ $client->setSecret($secret);
|
|
|
|
+ }
|
|
|
|
+ $client->setRedirectUris(array(
|
|
|
|
+ $redirectUri,
|
|
|
|
+ ));
|
|
|
|
+ $client->setAllowedGrantTypes(array_keys(OAuthClient::getGrantTypesChoices()));
|
|
|
|
+ $clientManager->updateClient($client);
|
|
}
|
|
}
|
|
- $client->setRedirectUris(array(
|
|
|
|
- $redirectUri,
|
|
|
|
- ));
|
|
|
|
- $client->setAllowedGrantTypes(array_keys(OAuthClient::getGrantTypesChoices()));
|
|
|
|
- $clientManager->updateClient($client);
|
|
|
|
-
|
|
|
|
|
|
+
|
|
return $client;
|
|
return $client;
|
|
}
|
|
}
|
|
|
|
|