简体   繁体   中英

facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1

I have followed the tutotial http://m2mdas.github.io/blog/2013/11/21/integrate-hwioauthbundle-with-fosuserbundle/ to make the Github login work, it almost seems to be working as when i clicked login i land up on the github login page, and i could see 1 user registered on my github application in github dashboard. But i am not authencated in Symfony. On my symfony tool bar on the bottom it still says that i am an anonymous user, plus a new row was not added to my table fos_user.

For facebook login, when i click on the generator login link for facebook, it gives me the error "Given URL is not permitted by the application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

Another doubt that i had is that in the tutorial, in routing.yml it says to put,

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

As there is no controller or resource specified, what am i supposed to put here as controller action path or resource?

config.yml

fos_user: db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel' firewall_name: main user_class: Les\\UserBundle\\Entity\\User registration: confirmation: enabled: true

hwi_oauth: # name of the firewall in which this bundle is active, this setting MUST be set firewall_name: secure_area connect: confirmation: 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

security: encoders: FOS\\UserBundle\\Model\\UserInterface: sha512

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 }

entity/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. The error:

    "Given URL is not permitted by the application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

    Happens when the domain from which you log into the Facebook app does not match the App Domain you have set up on the Settings tab of your Facebook Application.

    For instance, if you log in from "http:/www.yoursite.com", you need to go and set "yoursite.com" as the App domain on the Application.

  2. As far as the other problem you have, not being able to insert the users in the database, please check the following guide, which not only registers, but also auto-logins the user after registration:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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