OAuthClientCreateCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Base\OAuthServerBundle\Command;
  3. use \Base\OAuthServerBundle\Entity\OAuthClient;
  4. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. class OAuthClientCreateCommand extends ContainerAwareCommand
  9. {
  10. protected function configure()
  11. {
  12. $this
  13. ->setName('oauth:client:create')
  14. ->setDescription('Create OAuht client')
  15. ->setHelp('This command allows you to create an OAuth client')
  16. ->addOption(
  17. 'redirect_uri',
  18. 'r',
  19. InputOption::VALUE_REQUIRED,
  20. 'OAuth Redirect URI',
  21. 'http://127.0.0.1/ftth/app_dev.php/login_check'
  22. );
  23. }
  24. /**
  25. * @param InputInterface $input
  26. * @param OutputInterface $output
  27. */
  28. protected function execute(InputInterface $input, OutputInterface $output)
  29. {
  30. $clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
  31. $client = $clientManager->createClient();
  32. $client->setRedirectUris(array(
  33. $input->getOption('redirect_uri'),
  34. ));
  35. $client->setAllowedGrantTypes(array_keys(OAuthClient::getGrantTypesChoices()));
  36. $clientManager->updateClient($client);
  37. $output->writeln('OAuth client successfully generated!');
  38. $output->writeln('<info>client_id:</info> '.$client->getPublicId());
  39. $output->writeln('<info>client_secret:</info> '.$client->getSecret());
  40. }
  41. }