2
votes

I am having trouble implementing HWIOAuthBundle for google login/signup with my current application which has a custom authentication (not using FOSUserBundle).

To start off, I am getting a 404 error when trying to connect to "xxxx/connect/google". Where can I see the listed paths for HWIOAuthBundle that I can use in my twig file?

Login Twig:

<a href="{{ path('hwi_oauth_service_redirect', {'service' : 'google'}) }}" 
    class="google-login">Google</a>

routing.yml:

google_login:
    path: /login/check-google

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

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

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

config.yml

hwi_oauth:
    firewall_names: [main]
    resource_owners:
        google:
            type:                google
            client_id:           ?
            client_secret:       ?
            scope:               "email profile"

security.yml:

security:
    providers:
        db_provider:
            entity:
                class: AppBundle:User
                property: email
        my_custom_hwi_provider:
            id: ib_user.oauth_user_provider
    firewalls:
        main:
            oauth:
                resource_owners:
                    google: "/login/check-google"
                login_path: /login
                failure_path: /login
                oauth_user_provider:
                    service: ib_user.oauth_user_provider

User.php:

class User extends OAuthUser implements UserInterface {
    //added googleId attribute and setters/getter
    //also added the "extends OAuthUser"
}

OAuthProvider.php is also a new class that I added.

1
bin/console debug:router should reveal available routes.Cerad
How do I get the HWIOAuth routes that I need to redirect to google. I thought I had it imported on routing.yml?Brian Chen

1 Answers

2
votes

As the first comment says, debugging routes command is:

php bin/console debug:router

One problem could be missing access control path for connect in security.yml:

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