0

I get an Access Token from a social network help with HWIO Bundle and to redirect after service is called. I tried adding router to the service:

<argument type="service" id="router" />
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class UserProvider implements OAuthAwareUserProviderInterface
{
    protected $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    public function connect(UserInterface $user, UserResponseInterface $response)
    {
        $service = $response->getResourceOwner()->getName();
        $serviceProvider = $service."Provider";

        $user = $this->$serviceProvider->setUserData($user, $response);
        $grabProject = $this->grabProject->grabProject($response->getAccessToken(), $user);

        return new RedirectResponse($this->router->generate('application_frontend_default_index'));
     }

after my action I turn in controller HWIO Bundle in connectServiceAction

public function connectServiceAction(Request $request, $service)
{

Maybe need overwrite this controller and action, how to make this?

shuba.ivan
  • 3,824
  • 8
  • 49
  • 121
  • 3
    Please paste us the code of where your `connect` method is used. Also, it is usually a bad practice to generate Repsonses in services, this is the Controller's role to redirect of return Responses. – Terenoth Feb 03 '16 at 09:36
  • I update question? maybe need overwrite this action? – shuba.ivan Feb 03 '16 at 15:17

1 Answers1

0

The controller does not redirect because you did not return the RedirectResponse returned by your method when it is called. If you want a quick fix to make it work, just replace:

$this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation);

by:

return $this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation);

However, as I told you in my comment: this should not be your service's responsibility to redirect. You should do that in your Controller, right after your connect call.

Terenoth
  • 2,458
  • 1
  • 14
  • 21