OAuthClientCreateCommand.php 1.5 KB

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