Created
March 1, 2013 00:12
-
-
Save ornj/5061326 to your computer and use it in GitHub Desktop.
Symfony2 command for creating a Client for FOSOAuthServerBundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Bundle\OAuthBundle\Command; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class ClientCreateCommand extends ContainerAwareCommand | |
{ | |
protected function configure () | |
{ | |
$this | |
->setName('acme:oauth:client:create') | |
->setDescription('Creates a new client') | |
->addOption('redirect-uri', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Sets the redirect uri. Use multiple times to set multiple uris.', null) | |
->addOption('grant-type', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Set allowed grant type. Use multiple times to set multiple grant types', null) | |
; | |
} | |
protected function execute (InputInterface $input, OutputInterface $output) | |
{ | |
$clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default'); | |
$client = $clientManager->createClient(); | |
$client->setRedirectUris($input->getOption('redirect-uri')); | |
$client->setAllowedGrantTypes($input->getOption('grant-type')); | |
$clientManager->updateClient($client); | |
$output->writeln(sprintf('Added a new client with public id <info>%s</info>.', $client->getPublicId())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment