John the Ripper
John the Ripper

Reputation: 2439

Trying to Inject Parameters into Custom OAuthUserProvider

I followed the example here to add HWIOAuthBundle after struggling with the documentation. I get redirected to Google just fine but when it returns I get a warning that the first parameter is missing.

config.yml

services:
    wxexchange_oauth_user_provider:
        class:      WX\ExchangeBundle\Service\OAuthUserProvider
        arguments:  [@session, @doctrine, @service_container]
hwi_oauth:
    resource_owners:
        google:
            type:                google
            client_id:           xxxxxx
            client_secret:       xxxxx
            scope:               "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
       user_response_class: \WX\ExchangeBundle\Service\OAuthUserProvider
    firewall_name:               main

security.yml

providers:
    my_custom_hwi_provider:
        id: wxexchange_oauth_user_provider 

firewalls:
    main:
        pattern: ^/
        anonymous: ~
        provider: main
        form_login:
            check_path: login_check
            login_path: /Login
            csrf_provider: form.csrf_provider
        logout:
            path: logout
        oauth:
            resource_owners:
                facebook:           "/Login/OAuth/check-facebook"
                google:             "/Login/OAuth/check-google"
            login_path:        /Login/OAuth
            use_forward:       false
            failure_path:      /Login
            oauth_user_provider:
                service: wxexchange_oauth_user_provider

routing.yml

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

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

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

google_login:
    pattern: /Login/OAuth/check-google

facebook_login:
    pattern: /Login/OAuth/check-facebook

OAuthUserProvider.php

class OAuthUserProvider extends BaseOAuthUserProvider
{
    protected $session, $doctrine, $admins;
    public function __construct($session, $doctrine, $service_container)
    {
        $this->session = $session;
        $this->doctrine = $doctrine;
        $this->container = $service_container;
    }
    public function loadUserByUsername($username)
    {
        //code
    }
    public function loadUserByOAuthUserResponse(UserResponseInterface $response)
    {
        //code
    }
}

Error:

Warning: Missing argument 1 for WX\ExchangeBundle\Service\OAuthUserProvider::__construct(), called in /opt/lampp/htdocs/workoutexchange/trunk/WorkoutExchange/vendor/hwi/oauth-bundle/HWI/Bundle/OAuthBundle/OAuth/ResourceOwner/AbstractResourceOwner.php on line 186 and defined in /opt/lampp/htdocs/workoutexchange/trunk/WorkoutExchange/src/WX/ExchangeBundle/Service/OAuthUserProvider.php on line 13

Upvotes: 0

Views: 977

Answers (2)

georgeok
georgeok

Reputation: 5696

I was struggling with this error a long time.

providers:
--->>>my_custom_hwi_provider:
---->>>>>>> id: wxexchange_oauth_user_provider

Comment these two lines. You declare the service in the firewall section. You don't have to declare it as a provider.

After this you problem will be solved...

firewalls:
........
        oauth:
            resource_owners:
                facebook:           "/Login/OAuth/check-facebook"
                google:             "/Login/OAuth/check-google"
            login_path:        /Login/OAuth
            use_forward:       false
            failure_path:      /Login
            oauth_user_provider:
                service: wxexchange_oauth_user_provider

Upvotes: 0

shirshir
shirshir

Reputation: 111

This line in the services: section in config.yml is wrong:

    user_response_class: \WX\ExchangeBundle\Service\OAuthUserProvider

See the configuration reference here. I am not sure what it needs to be (the Google Oauth example does not mention it), but I think it should be a simple value object, and not your user provider.

Upvotes: 0

Related Questions