我从HWIO Bundle的社交网络帮助中获取访问令牌,并在调用服务后重定向。我尝试将路由器添加到服务中:
<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'));
}
在我的操作之后,我在connectServiceAction
中打开控制器HWIO Bundlepublic function connectServiceAction(Request $request, $service)
{
也许需要覆盖这个控制器和动作,如何制作这个?
答案 0 :(得分:0)
控制器不会重定向,因为在调用方法时,您没有return
方法返回的RedirectResponse
。如果您想要快速修复以使其工作,只需替换:
$this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation);
由:
return $this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation);
但是,正如我在评论中告诉你的那样:这不应该是您的服务重定向的责任。您应该在connect
电话后立即在您的控制器中执行该操作。