【问题标题】:Symfony2 HWIOauthBundle error with responseSymfony2 HWIOauthBundle 错误与响应
【发布时间】:2013-09-06 10:32:04
【问题描述】:

我希望任何人都可以回答我的以下问题。

我用 symgfony2 运行一个项目。我将为用户提供从 Linkedin 或 XING 等外部平台导入他们的简历。

我不需要为用户提供通过linkedin 或Xing 登录我的网站的能力。

所以我虽然可以使用 HwioAuthBundle,但我不知道该怎么做!

目前我在linkedin上登录页面是这样的,但是当我回到我的网站时,我得到了错误:

"""

Controller "XXXXX\MyBundle\Controller\MyController::importProfileLinkedinAction()" requires that you provide a value for the "$response" argument (because there is no default value or because there is a non optional argument after this one). 

"""

我按照文档中的说明进行操作:

config.yml

hwi_oauth:
  firewall_name: secured_area
  resource_owners:
      linkedin:
         type:          linkedin
         client_id:     XXXXXXXXXXXXXXXX
         client_secret: XXXXXXXXXXXXXXXX
         scope:         r_fullprofile
         infos_url:     "http://api.linkedin.com/v1/people/~:(id,formatted
                         name,recommendations-received)"          
services:
   oauth_user_provider:
       class: HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider

security.yml

        secured_area:
        oauth:
            resource_owners:
              linkedin:             /login/linkedin
            login_path:        /secured/login
            failure_path:      /secured/login

            oauth_user_provider:
                oauth: ~

routing.yml

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

linkedin:
  pattern:  /login/linkedin
  defaults:
    _controller: MYBundle:MyController:importProfileLinkedin

MyController.php

use \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
...
    public function importProfileLinkedinAction(Request $request, UserResponseInterface $response)

{
    $data = $response->getResponse(); /* this method should return all data that was sent from resource owner ???*/
    var_dump(
        $data
    );
    exit;
}

谢谢

【问题讨论】:

    标签: php symfony oauth hwioauthbundle


    【解决方案1】:

    重写捆绑控制器是个坏主意,因为逻辑比简单的读取请求和返回响应要复杂得多。请看official documentation

    您的问题是 $response 从未在全球范围内公开,它被隐藏以供内部使用 bundle 并且仅在少数地方提供。因此,要正确执行此操作,您需要实现自己的提供程序并覆盖以下功能:loadUserByOAuthUserResponse(UserResponseInterface $response),并保存所需的数据,即在会话中。

    【讨论】:

    • 您好,感谢您的回答!我删除了我的缓存,现在我得到了一个例外。未捕获的异常 'Symfony\\Component\\Config\\Definition\\Exception\\InvalidConfigurationException' 带有消息'必须配置路径“security.firewalls.secured_area.oauth”处的子节点“login_path”。'
    • 你是怎么做到的,我在 facebook 上遇到了同样的错误。 ?任何解决方案 // 可观的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多