瀏覽代碼

commit inicial

Guillermo Espinoza 8 年之前
當前提交
1d150ad8c1

+ 9 - 0
BaseOAuthBundle.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Base\OAuthBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class BaseOAuthBundle extends Bundle
+{
+}

+ 39 - 0
Command/CreateOAuthClientCommand.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace Base\OAuthBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class CreateOAuthClientCommand extends ContainerAwareCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('oauth:client:create')
+            ->setDescription('Create OAuht client')
+            ->setHelp('This command allows you to create an OAuth client')
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
+        
+        $client = $clientManager->createClient();
+        $client->setRedirectUris(array('http://127.0.0.1'));
+        $client->setAllowedGrantTypes(array('password', 'token', 'authorization_code'));
+        $clientManager->updateClient($client);
+        
+        $output->writeln('OAuth client successfully generated!');
+        $output->writeln('<info>client_id:</info> '.$client->getPublicId());
+        $output->writeln('<info>client_secret:</info> '.$client->getSecret());
+    }
+
+}

+ 28 - 0
DependencyInjection/BaseOAuthExtension.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Base\OAuthBundle\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\Loader;
+
+/**
+ * This is the class that loads and manages your bundle configuration.
+ *
+ * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
+ */
+class BaseOAuthExtension extends Extension
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function load(array $configs, ContainerBuilder $container)
+    {
+        $configuration = new Configuration();
+        $config = $this->processConfiguration($configuration, $configs);
+
+        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+        $loader->load('services.yml');
+    }
+}

+ 29 - 0
DependencyInjection/Configuration.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace Base\OAuthBundle\DependencyInjection;
+
+use Symfony\Component\Config\Definition\Builder\TreeBuilder;
+use Symfony\Component\Config\Definition\ConfigurationInterface;
+
+/**
+ * This is the class that validates and merges configuration from your app/config files.
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
+ */
+class Configuration implements ConfigurationInterface
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function getConfigTreeBuilder()
+    {
+        $treeBuilder = new TreeBuilder();
+        $rootNode = $treeBuilder->root('base_o_auth');
+
+        // Here you should define the parameters that are allowed to
+        // configure your bundle. See the documentation linked above for
+        // more information on that topic.
+
+        return $treeBuilder;
+    }
+}

+ 32 - 0
Entity/AccessToken.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Base\OAuthBundle\Entity;
+
+use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class AccessToken extends BaseAccessToken
+{
+
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer")
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    protected $id;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="OAuthClient")
+     * @ORM\JoinColumn(nullable=false)
+     */
+    protected $client;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="Base\UserBundle\Entity\User")
+     */
+    protected $user;
+
+}

+ 32 - 0
Entity/AuthCode.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Base\OAuthBundle\Entity;
+
+use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class AuthCode extends BaseAuthCode
+{
+
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer")
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    protected $id;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="OAuthClient")
+     * @ORM\JoinColumn(nullable=false)
+     */
+    protected $client;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="Base\UserBundle\Entity\User")
+     */
+    protected $user;
+
+}

+ 27 - 0
Entity/OAuthClient.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace Base\OAuthBundle\Entity;
+
+use FOS\OAuthServerBundle\Entity\Client as BaseClient;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class OAuthClient extends BaseClient
+{
+
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer")
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    protected $id;
+
+    
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+}

+ 32 - 0
Entity/RefreshToken.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Base\OAuthBundle\Entity;
+
+use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class RefreshToken extends BaseRefreshToken
+{
+
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer")
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    protected $id;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="OAuthClient")
+     * @ORM\JoinColumn(nullable=false)
+     */
+    protected $client;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="Base\UserBundle\Entity\User")
+     */
+    protected $user;
+
+}

+ 0 - 0
Resources/config/routing.yml


+ 4 - 0
Resources/config/services.yml

@@ -0,0 +1,4 @@
+services:
+#    base_o_auth.example:
+#        class: Base\OAuthBundle\Example
+#        arguments: ["@service_id", "plain_value", "%parameter%"]

+ 10 - 0
composer.json

@@ -0,0 +1,10 @@
+{
+    "name": "base-oauth-bundle",
+    "description": "Flowdat 3 Base OAuth Bundle",
+    "keywords": ["Admin Generator", "admin", "oauth", "bundle"],
+    "autoload": {
+        "psr-4": { "Base\\OAuthBundle\\": "" }
+    },
+	"version": "1.0",
+  	"minimum-stability": "stable"
+}