-->

Symfony2 HWIOauthBundle error with response

2019-08-15 02:06发布

问题:

i hope anybody can answer my below question.

I running a project with symgfony2. I will offer users to import their CV from external plattforms like Linkedin or XING.

What i dont need is offering the user the ability to login to my site through linkedin or Xing.

So i though i can use for this the HwioAuthBundle but i can not figure it out, how to do this!

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:

"""

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

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;
}

Thanks

回答1:

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. 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 i.e. in session.