简体   繁体   English

Symfony2 HWIOauthBundle错误,响应

[英]Symfony2 HWIOauthBundle error with response

i hope anybody can answer my below question. 我希望任何人都可以回答我下面的问题。

I running a project with symgfony2. 我用symgfony2运行一个项目。 I will offer users to import their CV from external plattforms like Linkedin or XING. 我将为用户提供从Linkedin或XING之类的外部平台导入其简历的功能。

What i dont need is offering the user the ability to login to my site through linkedin or Xing. 我不需要为用户提供通过Linkedin或Xing登录到我的网站的功能。

So i though i can use for this the HwioAuthBundle but i can not figure it out, how to do this! 因此,尽管我可以为此使用HwioAuthBundle,但我不知道该怎么做!

At the moment is it like this that i come to loginpage on linkedin but when i come back to my site then i get the error: 目前是这样,我来到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). 

""" “””

I do it as described in the documentation: 我按照文档中的说明进行操作:

config.yml 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 security.yml

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

            oauth_user_provider:
                oauth: ~

routing.yml 使用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 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;
}

Thanks 谢谢

Overwriting bundle controller is bad idea, as logic is much more complicated than simple read request and return response. 覆盖包控制器不是一个好主意,因为逻辑比简单的读取请求和返回响应要复杂得多。 Please have a look at official documentation . 请查看官方文档

Your problem is that $response is never exposed globally, it's hidden for internal use of bundle and given only in few places. 您的问题是$response永远不会在全局范围内公开,它对于内部使用bundle是隐藏的,并且只在少数地方提供。 So to do this correctly you would need to implement own provider and overwrite the functionality of: loadUserByOAuthUserResponse(UserResponseInterface $response) , and save the required data ie in session. 因此,要正确执行此操作,您将需要实现自己的提供程序并覆盖以下功能: loadUserByOAuthUserResponse(UserResponseInterface $response) ,并在会话中保存所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM