-->

Symfony2的HWIOauthBundle误差与响应(Symfony2 HWIOauthBund

2019-10-18 13:54发布

我希望有人能回答我的问题如下。

我跑与symgfony2的项目。 我会提供给用户从外部plattforms像LinkedIn或XING导入他们的简历。

什么我不需要是为用户提供通过LinkedIn或兴登录到我的网站的能力。

所以,我虽然我可以使用这个HwioAuthBundle,但我不能弄清楚,如何做到这一点!

目前是这样的,我来loginpage在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;
}

谢谢

Answer 1:

重写束控制器是坏主意,作为逻辑比简单的读取请求要复杂得多,并返回响应。 请看看官方文档 。

你的问题是, $response永远不会暴露在全球,它是隐藏在内部使用捆绑的,只在少数地方给出。 因此,要做到这一点正确,您需要实现自己的供应商,覆盖的功能: loadUserByOAuthUserResponse(UserResponseInterface $response) ,并保存在IE会话所需的数据。



文章来源: Symfony2 HWIOauthBundle error with response