繁体   English   中英

facebook和github登录Symfony2.1中的HWIOAuthBundle和FOSUserBundle

[英]facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1

我已经按照Tututial http://m2mdas.github.io/blog/2013/11/21/integrate-hwioauthbundle-with-fosuserbundle/的要求进行了Github登录工作,这似乎和我单击登录时一样有效登陆github登录页面,我可以在github仪表板上的github应用程序上看到1个用户注册。 但是我没有在Symfony中得到认证。 在我底部的symfony工具栏上,它仍然说我是一个匿名用户,并且还没有在表fos_user中添加新行。

对于facebook登录,当我单击facebook的生成器登录链接时,它给我错误“应用程序配置不允许给定URL 。:应用程序的设置不允许一个或多个给定URL。它必须匹配网站URL或Canvas URL,或者域必须是该应用程序域之一的子域。”

我的另一个疑问是,在教程中,它说要放在routing.yml中,

            hwi_github_login:
                pattern: /secure_area/login/check-github

由于未指定控制器或资源,我应该在此处输入什么作为控制器操作路径或资源?

config.yml

fos_user:db_driver:orm#其他有效值是'mongodb','couchdb'和'propel'Firewall_name:主user_class:Les \\ UserBundle \\ Entity \\ User注册:确认:启用:true

hwi_oauth:#此捆绑包在其中处于活动状态的防火墙的名称,必须设置以下设置firewall_name:secure_area connect:确认:true #account_connector:hwi_oauth.user.provider.fosub_bridge #registration_form_handler:hwi_oauth.registration.form.handler.fosub_bridge# registration_form:fos_user.registration.form

resource_owners:
    github:
        type:                github
        client_id:           b625ec98906cc26ad4f1
        client_secret:       a3505d93ab1fc6c5a7fa2805c0723bbfddf556a7
        scope:               "user:email"
    facebook:
        type:                facebook
        client_id:           331922526960400
        client_secret:       9dc32a145a1c6b0b7f5e57a34d174011
fosub:
    # try 30 times to check if a username is available (foo, foo1, foo2 etc)
    username_iterations: 30

    # mapping between resource owners (see below) and properties
    properties:
        github: githubID
        facebook: fbID

security.yml

安全性:编码器:FOS \\ UserBundle \\ Model \\ UserInterface:sh​​a512

role_hierarchy:
    ROLE_CLIENT:      ROLE_USER
    ROLE_RESTO:       ROLE_CLIENT
    ROLE_ADMIN:       [ ROLE_USER, ROLE_CLIENT, ROLE_RESTO ]
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
                pattern: ^/
                form_login:
                    provider: fos_userbundle
                    csrf_provider: form.csrf_provider
                logout:       true
                anonymous:    true

    secure_area:
                pattern: ^/secure_area

                oauth:
                        failure_path: /secure_area/connect
                        login_path: /secure_area/connect
                        check_path: /secure_area/connect
                        provider: fos_userbundle
                        resource_owners:
                              github:           "/secure_area/login/check-github"
                              facebook:         "/secure_area/login/check-facebook"
                        oauth_user_provider:
                              service: hwi_oauth.user.provider.fosub_bridge

                anonymous:    true
                logout:
                         path:           /secure_area/logout
                         target:         / #where to go after logout



access_control:
     - { path: ^/booking, role: ROLE_CLIENT }
     - { path: ^/party_calendar, role: ROLE_CLIENT }
     - { path: ^/restaurant_admin, role: ROLE_RESTO }

     - { path: ^/secure_area/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/secure_area/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/secure_area, role: ROLE_USER }

使用routing.yml

       fos_user_security:
           resource: "@FOSUserBundle/Resources/config/routing/security.xml"
           prefix: /login

       fos_user_profile:
           resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
           prefix: /profile

       fos_user_register:
           resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
           prefix: /register

       fos_user_resetting:
           resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
           prefix: /resetting

       fos_user_change_password:
           resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
           prefix: /profile



       hwi_oauth_redirect:
           resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
           prefix:   /secure_area/connect

       hwi_oauth_login:
           resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
           prefix:   /secure_area/connect

       hwi_oauth_connect:
           resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
           prefix:   /secure_area/connect

       hwi_github_login:
           pattern: /secure_area/login/check-github
           defaults: { _controller: LesCouvertsBundle:Couverts:index }


       hwi_facebook_login:
           pattern: /secure_area/login/check-facebook
           defaults: { _controller: LesCouvertsBundle:Couverts:index }

       hwi_google_login:
           pattern: /secure_area/login/check-google
           defaults: { _controller: LesCouvertsBundle:Couverts:index }

实体/ user.php的

       /**
        * @ORM\Entity
        * @ORM\Table(name="fos_user")
        */
       class User extends BaseUser{
           /**
            * @ORM\Id
            * @ORM\Column(type="integer")
            * @ORM\GeneratedValue(strategy="AUTO")
            */
           protected $id;

           /**
            * @var string
            *
            * @ORM\Column(name="githubId", type="string", nullable=true)
            */
           private $githubID;


           /**
            * @var string
            *
            * @ORM\Column(name="githubId", type="string", nullable=true)
            */
           private $fbID;



           public function __construct()
           {
               parent::__construct();
               // your own logic
           }

           /**
            * Get id
            *
            * @return integer 
            */
           public function getId()
           {
               return $this->id;
           }

           /**
            * @param string $githubID
            */
           public function setGithubID($githubID)
           {
               $this->githubID = $githubID;
           }

           /**
            * @return string
            */
           public function getGithubID()
           {
               return $this->githubID;
           }

           /**
            * @param string $fbID
            */
           public function setFbID($fbID)
           {
               $this->fbID = $fbID;
           }

           /**
            * @return string
            */
           public function getFbID()
           {
               return $this->fbID;
           }



       }
  1. 错误:

    “应用程序配置不允许使用URL 。:应用程序的设置不允许使用一个或多个给定URL。它必须与网站URL或Canvas URL匹配,或者该域必须是该应用程序域之一的子域“。

    当您登录Facebook应用程序的域与您在Facebook应用程序的“设置”选项卡上设置的应用程序域不匹配时发生。

    例如,如果您从“ http:/www.yoursite.com”登录,则需要将“ yoursite.com”设置为应用程序上的应用程序域。

  2. 关于您无法将用户插入数据库的其他问题,请检查以下指南,该指南不仅进行注册,而且在注册后自动登录用户:

    https://gist.github.com/danvbe/4476697

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM