1

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

我用 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). 

"""

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

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

安全.yml

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

            oauth_user_provider:
                oauth: ~

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

谢谢

4

1 回答 1

2

覆盖捆绑控制器是个坏主意,因为逻辑比简单的读取请求和返回响应要复杂得多。请查看官方文档

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

于 2013-09-03T10:01:42.460 回答