0

在阅读文档后,我按照此处的示例添加了 HWIOAuthBundle。我被重定向到谷歌就好了,但是当它返回时,我收到一个警告说第一个参数丢失。

配置.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

安全.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

路由.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
    }
}

错误:

警告:WX\ExchangeBundle\Service\OAuthUserProvider::__construct() 缺少参数 1,在 /opt/lampp/htdocs/workoutexchange/trunk/WorkoutExchange/vendor/hwi/oauth-bundle/HWI/Bundle/OAuthBundle/OAuth/ 中调用第 186 行的 ResourceOwner/AbstractResourceOwner.php 并在第 13 行的 /opt/lampp/htdocs/workoutexchange/trunk/WorkoutExchange/src/WX/ExchangeBundle/Service/OAuthUserProvider.php 中定义

4

2 回答 2

0

services:节中的这一行config.yml是错误的:

    user_response_class: \WX\ExchangeBundle\Service\OAuthUserProvider

请参阅此处的配置参考。我不确定它需要是什么(Google Oauth 示例没有提及),但我认为它应该是一个简单的值对象,而不是您的用户提供程序。

于 2014-06-11T15:45:34.057 回答
0

我为这个错误苦苦挣扎了很长时间。

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

注释这两行。您在防火墙部分声明该服务。您不必将其声明为提供者。

在此之后,您的问题将得到解决...

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
于 2015-02-05T20:09:15.633 回答