Search code examples
phpsymfonyoauthhwioauthbundle

HWIOAuthBundle `An authentication exception occurred`


I have problem with HWIOAuthBundle (FOSUserBundle integration.)

Click the link /connect/google, this screen appeares. enter image description here (Screen is blurred , because it is client's email)

then go back to callback URL /login/check-google

it redirected to /login and show this message

An authentication exception occurred.

If I type /login/check-google directly, nothing happens and just redirected to login.

I have no clue what hanneped on /login/check-google page.

How can I check??? (I am stuck in this problem for one week, I brush-up and updated article.)

My environments are

  • Symfony 2.8.14
  • HWIOAuthBundle 0.6.0
  • FOSUserBundle 2.0.1

security.yml

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

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
                # if you are using Symfony < 2.8, use the following config instead:
                # csrf_provider: form.csrf_provider

            logout:       true
            anonymous:    true
            oauth:
                resource_owners:
                    google:             "/login/check-google"
                login_path:        /login
                use_forward:       false
                failure_path:      /login
                oauth_user_provider:
                    service: my_user_provider
        login:
            pattern:  ^/login$
            security: false

    access_control:
         - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }

config.yml

hwi_oauth:
    connect:
        account_connector: my_user_provider
    firewall_names: [main]
    fosub:
        username_iterations: 30
        properties:
            google: google_id
    resource_owners:
        google:
            type:                google
            client_id:           XXXXXXXX
            client_secret:       XXXXXXXXXX
            scope:               "email profile"

service.xml

    <parameters>
     <parameter key="my_user_provider.class">Acme\UserBundle\Security\Core\User\FOSUBUserProvider</parameter>
    </parameters>
    <services>
          <service id="my_user_provider" class="%my_user_provider.class%">
            <argument type="service" id="fos_user.user_manager"/>
            <argument type="service" id="service_container" />

            <argument type="collection">
                <argument key="google">google_id</argument>       
            </argument>   
        </service>
    </services>

routing.yml

admin_area:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

acme_member:
    resource: "@AcmeMemberBundle/Resources/config/routing.yml"
    prefix:   /member

_user_bundle:
    resource: "@UserBundle/Resources/config/routing.yml"

acme_top:
    resource: "@AcmeTopBundle/Resources/config/routing.yml"
    prefix:   /

fos_user_group:
    resource: "@FOSUserBundle/Resources/config/routing/group.xml"
    prefix: /group


sonata_page_cache:
    resource: '@SonataCacheBundle/Resources/config/routing/cache.xml'
    prefix: /

#HWIOAuthBundle routes
hwi_oauth_security:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix: /login

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

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

facebook_login:
    path: /login/check-facebook

google_login:
    path: /login/check-google


fos_js_routing:
  resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

Solution

  • I solved my problem.

    Downgrade >>> HWIAuthBundle 0.4.3

    and add this in config.yml

    hwi_oauth:
        http_client:
            verify_peer: false
    

    This is because of https / http difference. Google requests https. However it skips the https verification.

    check the last comment also.

    https://github.com/hwi/HWIOAuthBundle/issues/1024