瀏覽代碼

refactory

Guillermo Espinoza 8 年之前
父節點
當前提交
d1d514d3b5

+ 0 - 9
BaseOAuthBundle.php

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

+ 9 - 0
BaseOAuthClientBundle.php

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

+ 0 - 46
Command/OAuthClientCreateCommand.php

@@ -1,46 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\Command;
-
-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 OAuthClientCreateCommand extends ContainerAwareCommand
-{
-
-    protected function configure()
-    {
-        $this
-            ->setName('oauth:client:create')
-            ->setDescription('Create OAuht client')
-            ->setHelp('This command allows you to create an OAuth client')
-            ->addOption(
-                'redirect_uri',
-                'r',
-                InputOption::VALUE_REQUIRED,
-                'OAuth Redirect URI',
-                'http://127.0.0.1'
-            );
-    }
-
-    /**
-     * @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($input->getOption('redirect_uri')));
-        $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());
-    }
-
-}

+ 0 - 42
Controller/OAuthController.php

@@ -1,42 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\Controller;
-
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\JsonResponse;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-
-class OAuthController extends Controller
-{
-
-    /**
-     * @Route("/login_check", name="login_check")
-     * @param Request $request
-     * @return type
-     */
-    public function loginCheckAction(Request $request)
-    {
-        return $this->redirect($this->generateUrl('sonata_admin_dashboard'));
-    }
-
-    /**
-     * @Route("/api/user/me", name="user_data_json")
-     * @return JsonResponse
-     */
-    public function getUserDataJsonAction()
-    {
-        $user = $this->getUser();
-        $data = array();
-        if ($user) {
-            $data['id'] = $user->getId();
-            $data['username'] = $user->getUsername();
-            $data['firstname'] = $user->getFirstname();
-            $data['lastname'] = $user->getLastname();
-            $data['roles'] = $user->getRoles();
-        }
-
-        return new JsonResponse($data);
-    }
-
-}

+ 0 - 93
Controller/SecurityController.php

@@ -1,93 +0,0 @@
-<?php
-
-/*
- * This file is part of the FOSUserBundle package.
- *
- * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Base\OAuthBundle\Controller;
-
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Security\Core\Exception\AuthenticationException;
-use Symfony\Component\Security\Core\Security;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-
-class SecurityController extends Controller
-{
-    /**
-     * @Route("/oauth/v2/auth/login", name="oauth_login")
-     * @param Request $request
-     *
-     * @return Response
-     */
-    public function loginAction(Request $request)
-    {
-        /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
-        $session = $request->getSession();
-
-        $authErrorKey = Security::AUTHENTICATION_ERROR;
-        $lastUsernameKey = Security::LAST_USERNAME;
-
-        // get the error if any (works with forward and redirect -- see below)
-        if ($request->attributes->has($authErrorKey)) {
-            $error = $request->attributes->get($authErrorKey);
-        } elseif (null !== $session && $session->has($authErrorKey)) {
-            $error = $session->get($authErrorKey);
-            $session->remove($authErrorKey);
-        } else {
-            $error = null;
-        }
-
-        if (!$error instanceof AuthenticationException) {
-            $error = null; // The value does not come from the security component.
-        }
-
-        // last username entered by the user
-        $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);
-
-        $csrfToken = $this->has('security.csrf.token_manager')
-            ? $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue()
-            : null;
-
-        return $this->renderLogin(array(
-            'last_username' => $lastUsername,
-            'error' => $error,
-            'csrf_token' => $csrfToken,
-        ));
-    }
-
-    /**
-     * Renders the login template with the given parameters. Overwrite this function in
-     * an extended controller to provide additional data for the login template.
-     *
-     * @param array $data
-     *
-     * @return Response
-     */
-    protected function renderLogin(array $data)
-    {
-        return $this->render('@BaseOAuthBundle/Security/login.html.twig', $data);
-    }
-
-    /**
-     * @Route("/oauth/v2/auth/login_check", name="oauth_login_check")
-     */
-    public function checkAction()
-    {
-        throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
-    }
-
-    /**
-     * @Route("/oauth/v2/auth/logout", name="oauth_logout")
-     */
-    public function logoutAction()
-    {
-        throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
-    }
-}

+ 2 - 2
DependencyInjection/BaseOAuthExtension.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\DependencyInjection;
+namespace Base\OAuthClientBundle\DependencyInjection;
 
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\Config\FileLocator;
@@ -12,7 +12,7 @@ use Symfony\Component\DependencyInjection\Loader;
  *
  * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
  */
-class BaseOAuthExtension extends Extension
+class BaseOAuthClientExtension extends Extension
 {
     /**
      * {@inheritdoc}

+ 2 - 2
DependencyInjection/Configuration.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\DependencyInjection;
+namespace Base\OAuthClientBundle\DependencyInjection;
 
 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
 use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -18,7 +18,7 @@ class Configuration implements ConfigurationInterface
     public function getConfigTreeBuilder()
     {
         $treeBuilder = new TreeBuilder();
-        $rootNode = $treeBuilder->root('base_o_auth');
+        $rootNode = $treeBuilder->root('base_o_auth_client');
 
         // Here you should define the parameters that are allowed to
         // configure your bundle. See the documentation linked above for

+ 0 - 29
Entity/AccessToken.php

@@ -1,29 +0,0 @@
-<?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;
-
-    protected $user;
-
-}

+ 0 - 29
Entity/AuthCode.php

@@ -1,29 +0,0 @@
-<?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;
-
-    protected $user;
-
-}

+ 0 - 27
Entity/OAuthClient.php

@@ -1,27 +0,0 @@
-<?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();
-    }
-
-}

+ 0 - 29
Entity/RefreshToken.php

@@ -1,29 +0,0 @@
-<?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;
-
-    protected $user;
-
-}

+ 5 - 5
EventListener/DynamicRelationSubscriber.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\EventListener;
+namespace Base\OAuthClientBundle\EventListener;
 
 use Doctrine\ORM\Events;
 use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
@@ -26,9 +26,9 @@ class DynamicRelationSubscriber implements EventSubscriber
         // the $metadata is the whole mapping info for this class
         $metadata = $eventArgs->getClassMetadata();
         $classes = array(
-            'Base\OAuthBundle\Entity\AccessToken',
-            'Base\OAuthBundle\Entity\AuthCode',
-            'Base\OAuthBundle\Entity\RefreshToken'
+            'Base\OAuthServerBundle\Entity\AccessToken',
+            'Base\OAuthServerBundle\Entity\AuthCode',
+            'Base\OAuthServerBundle\Entity\RefreshToken'
         );
         
         if (!in_array($metadata->getName(), $classes)) {
@@ -36,7 +36,7 @@ class DynamicRelationSubscriber implements EventSubscriber
         }
         
         $userClass = 'Base\UserBundle\Entity\User';
-        $OAuthUserClass = '\Base\OAuthBundle\Security\Core\User\CustomOAuthUser';
+        $OAuthUserClass = 'Base\OAuthClientBundle\Security\Core\User\CustomOAuthUser';
         
         $metadata->mapManyToOne(array(
             'targetEntity'  => class_exists($userClass) ? $userClass : $OAuthUserClass,

+ 0 - 26
EventListener/OAuthEventListener.php

@@ -1,26 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\EventListener;
-
-use FOS\OAuthServerBundle\Event\OAuthEvent;
-
-class OAuthEventListener
-{
-
-    public function onPreAuthorizationProcess(OAuthEvent $event)
-    {
-        if ($user = $event->getUser()) {
-            $event->setAuthorizedClient($event->getClient());
-        }
-    }
-
-    public function onPostAuthorizationProcess(OAuthEvent $event)
-    {
-        if ($event->isAuthorizedClient()) {
-            if (null !== $client = $event->getClient()) {
-                $user = $event->getUser();
-            }
-        }
-    }
-
-}

+ 1 - 1
OAuth/Response/PathUserResponse.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\OAuth\Response;
+namespace Base\OAuthClientBundle\OAuth\Response;
 
 class PathUserResponse extends \HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse
 {

+ 0 - 14
Resources/config/fosoauthserverbundle/config.yml

@@ -1,14 +0,0 @@
-fos_oauth_server:
-    db_driver: orm       # Drivers available: orm, mongodb, or propel
-    client_class:        Base\OAuthBundle\Entity\OAuthClient
-    access_token_class:  Base\OAuthBundle\Entity\AccessToken
-    refresh_token_class: Base\OAuthBundle\Entity\RefreshToken
-    auth_code_class:     Base\OAuthBundle\Entity\AuthCode
-    service:
-        user_provider: fos_user.user_provider.username_email
-        options:
-            supported_scopes: user
-
-twig:
-    paths:
-        '%kernel.root_dir%/../vendor/base-oauth-bundle/Resources/views': BaseOAuthBundle            

+ 0 - 5
Resources/config/fosoauthserverbundle/routing.yml

@@ -1,5 +0,0 @@
-fos_oauth_server_token:
-    resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"
-
-fos_oauth_server_authorize:
-    resource: "@FOSOAuthServerBundle/Resources/config/routing/authorize.xml"

+ 0 - 6
Resources/config/fosoauthserverbundle/services.yml

@@ -1,6 +0,0 @@
-services:
-    oauth_event_listener:
-        class:  Base\OAuthBundle\EventListener\OAuthEventListener
-        tags:
-            - { name: kernel.event_listener, event: fos_oauth_server.pre_authorization_process, method: onPreAuthorizationProcess }
-            - { name: kernel.event_listener, event: fos_oauth_server.post_authorization_process, method: onPostAuthorizationProcess }

+ 3 - 3
Resources/config/hwioauthbundle/config.yml

@@ -8,7 +8,7 @@ hwi_oauth:
             authorization_url:   "%authorization_url%"
             infos_url:           "%infos_url%"
             scope:               "user"
-            user_response_class: Base\OAuthBundle\OAuth\Response\PathUserResponse
+            user_response_class: Base\OAuthClientBundle\OAuth\Response\PathUserResponse
             paths:
                 identifier: id
                 nickname: username
@@ -25,6 +25,6 @@ doctrine:
                 mappings:
                     custom_mapping:
                         type: annotation
-                        prefix: Base\OAuthBundle\Security\Core\User\
-                        dir: "%kernel.root_dir%/../vendor/base-oauth-bundle/Security/Core/User/"
+                        prefix: Base\OAuthClientBundle\Security\Core\User\
+                        dir: "%kernel.root_dir%/../vendor/base-oauth-client-bundle/Security/Core/User/"
                         is_bundle: false

+ 1 - 1
Resources/config/hwioauthbundle/services.yml

@@ -1,4 +1,4 @@
 services:
     base_oauth_bundle.oauth_user_provider:
-        class: Base\OAuthBundle\Security\Core\User\CustomOAuthUserProvider
+        class: Base\OAuthClientBundle\Security\Core\User\CustomOAuthUserProvider
         arguments: ["@security.token_storage"]

+ 0 - 4
Resources/config/routing.yml

@@ -1,4 +0,0 @@
-base_o_auth:
-    resource: "@BaseOAuthBundle/Controller/"
-    type:     annotation    
-    prefix:   /

+ 4 - 4
Resources/config/services.yml

@@ -1,5 +1,5 @@
 services:
-    oauth.user.mapping.listener:
-        class: Base\OAuthBundle\EventListener\DynamicRelationSubscriber
-        tags:
-            - { name: doctrine.event_listener, event: loadClassMetadata }
+#    oauth.user.mapping.listener:
+#        class: Base\OAuthClientBundle\EventListener\DynamicRelationSubscriber
+#        tags:
+#            - { name: doctrine.event_listener, event: loadClassMetadata }

+ 0 - 5
Resources/views/Security/login.html.twig

@@ -1,5 +0,0 @@
-{% extends "BaseOAuthBundle::layout.html.twig" %}
-
-{% block fos_user_content %}
-    {{ include("BaseOAuthBundle:Security:login_content.html.twig") }}
-{% endblock fos_user_content %}

+ 0 - 22
Resources/views/Security/login_content.html.twig

@@ -1,22 +0,0 @@
-{% trans_default_domain 'FOSUserBundle' %}
-
-{% if error %}
-    <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
-{% endif %}
-
-<form action="{{ path("oauth_login_check") }}" method="post">
-    {% if csrf_token %}
-        <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
-    {% endif %}
-
-    <label for="username">{{ 'security.login.username'|trans }}</label>
-    <input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />
-
-    <label for="password">{{ 'security.login.password'|trans }}</label>
-    <input type="password" id="password" name="_password" required="required" />
-
-    <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
-    <label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
-
-    <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
-</form>

+ 1 - 1
Security/Core/User/CustomOAuthUser.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Security\Core\User;
+namespace Base\OAuthClientBundle\Security\Core\User;
 
 use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser;
 use Doctrine\ORM\Mapping as ORM;

+ 2 - 2
Security/Core/User/CustomOAuthUserProvider.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Security\Core\User;
+namespace Base\OAuthClientBundle\Security\Core\User;
 
 use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
 use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider;
@@ -43,7 +43,7 @@ class CustomOAuthUserProvider extends OAuthUserProvider
      */
     public function supportsClass($class)
     {
-        return $class === 'Base\\OAuthBundle\\Security\\Core\\User\\CustomOAuthUser';
+        return $class === 'Base\\OAuthClientBundle\\Security\\Core\\User\\CustomOAuthUser';
     }
 
 }

+ 4 - 5
composer.json

@@ -1,13 +1,12 @@
 {
-    "name": "base-oauth-bundle",
-    "description": "Flowdat 3 Base OAuth Bundle",
+    "name": "base-oauth-client-bundle",
+    "description": "Flowdat 3 Base OAuth Client Bundle",
     "keywords": ["Admin Generator", "admin", "oauth", "bundle"],
     "require": {
-        "hwi/oauth-bundle": "^0.5.3",
-        "friendsofsymfony/oauth-server-bundle": "^1.5"
+        "hwi/oauth-bundle": "^0.5.3"
     },
     "autoload": {
-        "psr-4": { "Base\\OAuthBundle\\": "" }
+        "psr-4": { "Base\\OAuthClientBundle\\": "" }
     },
 	"version": "1.0",
   	"minimum-stability": "stable"