Jelajahi Sumber

Se creo un nuevo comando oauth:client:createRedirects donde se le pueden pasar varias redirecciones

gabriel 7 tahun lalu
induk
melakukan
a9332e743b

+ 1 - 1
Command/OAuthClientCreateCommand.php

@@ -16,7 +16,7 @@ class OAuthClientCreateCommand extends ContainerAwareCommand
     {
         $this
                 ->setName('oauth:client:create')
-                ->setDescription('Create OAuht client')
+                ->setDescription('Create OAuht client. DEPRECATED see oauth:client:createRedirects')
                 ->setHelp('This command allows you to create an OAuth client')
                 ->addOption(
                         'redirect_uri', null, InputOption::VALUE_REQUIRED, 'OAuth Redirect URI', 'http://127.0.0.1/ftth/app_dev.php/login_check'

+ 78 - 0
Command/OAuthClientCreateRedirectsCommand.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace Base\OAuthServerBundle\Command;
+
+use \Base\OAuthServerBundle\Entity\OAuthClient;
+use \FOS\OAuthServerBundle\Entity\ClientManager;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputOption;
+
+class OAuthClientCreateRedirectsCommand extends ContainerAwareCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('oauth:client:createRedirects')
+            ->setDescription('Create OAuht client for uri\'s.')
+            ->setHelp('This command allows you to create an OAuth client with many uri\'s')
+            ->addOption(
+                'redirect_uri', null, InputOption::VALUE_IS_ARRAY, 'OAuth Redirect URI', 'http://127.0.0.1/ftth/app_dev.php/login_check'
+            )
+            ->addOption(
+                'client_id', null, InputOption::VALUE_OPTIONAL, 'OAuth Client random Id'
+            )
+            ->addOption(
+                'client_secret', null, InputOption::VALUE_OPTIONAL, 'OAuth Client random Secret'
+            );
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $redirectUri = $input->getOption('redirect_uri');
+        $random = $input->getOption('client_id');
+        $secret = $input->getOption('client_secret');
+
+        $client = $this->createClient($redirectUri, $random, $secret);
+
+        $output->writeln('<info>OAUTH_CLIENT_ID</info>=' . $client->getPublicId());
+        $output->writeln('<info>OAUTH_CLIENT_SECRET</info>=' . $client->getSecret());
+    }
+
+    /**
+     * @param array $redirectUri
+     * @param string $random
+     * @param string $secret
+     *
+     * @return OAuthClient
+     */
+    protected function createClient($redirectUri, $random = null, $secret = null)
+    {
+        /* @var $clientManager ClientManager */
+        $clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
+
+        $em = $this->getContainer()->get('doctrine')->getEntityManager();
+        /* @var $client OAuthClient */
+        $client = $clientManager->createClient();
+        if ($random) {
+            $client->setRandomId($random);
+        }
+        if ($secret) {
+            $client->setSecret($secret);
+        }
+        $client->setRedirectUris(
+            $redirectUri
+        );
+        $client->setAllowedGrantTypes(array_keys(OAuthClient::getGrantTypesChoices()));
+        $clientManager->updateClient($client);
+
+        return $client;
+    }
+
+}