Newscoop\Tools\Console\Command\CreateOAuthClientCommand::execute PHP Method

execute() protected method

See also: Console\Command\Command
protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $container = $this->getApplication()->getKernel()->getContainer();
        $router = $container->get('router');
        $em = $container->getService('em');
        $clientManager = $container->get('fos_oauth_server.client_manager.default');
        $name = $input->getArgument('name');
        $publication = $em->getRepository('\\Newscoop\\Entity\\Aliases')->findOneByName($input->getArgument('publication'))->getPublication();
        $redirectUris = $input->getArgument('redirectUris');
        if (is_null($redirectUris)) {
            $redirectUris = $router->generate('oauth_authentication_result');
        }
        if ($input->getOption('default')) {
            $preferencesService = $container->get('preferences');
            $defaultClientName = 'newscoop_' . $preferencesService->SiteSecretKey;
            $client = $em->getRepository('\\Newscoop\\GimmeBundle\\Entity\\Client')->findOneByName($defaultClientName);
            if ($client) {
                return;
            }
        }
        $client = $clientManager->createClient();
        $client->setAllowedGrantTypes(array('token', 'authorization_code', 'client_credentials', 'password'));
        $client->setRedirectUris(array($redirectUris));
        $client->setName($name);
        $client->setPublication($publication);
        if ($input->getOption('test')) {
            $client->setRandomId('svdg45ew371vtsdgd29fgvwe5v');
            $client->setSecret('h48fgsmv0due4nexjsy40jdf3sswwr');
            $client->setTrusted(true);
        }
        if ($input->getOption('default')) {
            $client->setName($defaultClientName);
            $client->setTrusted(true);
        }
        $clientManager->updateClient($client);
    }
CreateOAuthClientCommand