CreateOAuthClientCommand.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. class CreateOAuthClientCommand extends ContainerAwareCommand
  7. {
  8. protected function configure()
  9. {
  10. $this
  11. ->setName('oauth:client:create')
  12. ->setDescription('Create OAuht client')
  13. ->setHelp('This command allows you to create an OAuth client')
  14. ;
  15. }
  16. /**
  17. * @param InputInterface $input
  18. * @param OutputInterface $output
  19. */
  20. protected function execute(InputInterface $input, OutputInterface $output)
  21. {
  22. $clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
  23. $client = $clientManager->createClient();
  24. $client->setRedirectUris(array('http://127.0.0.1'));
  25. $client->setAllowedGrantTypes(array('password', 'token', 'authorization_code'));
  26. $clientManager->updateClient($client);
  27. $output->writeln('OAuth client successfully generated!');
  28. $output->writeln('<info>client_id:</info> '.$client->getPublicId());
  29. $output->writeln('<info>client_secret:</info> '.$client->getSecret());
  30. }
  31. }