传递数组而不在url中显示


Pass an array without displaying it in url

我要做的事情:

我目前正在我的symfony2应用程序上通过领英OAuth安装身份验证。

在我的userController中,我有一个用于获取linkedin数据的函数,还有一个用于创建新用户的函数。

这创建了一个新的用户函数,可以处理linkedin用户(通过作为参数传递的数组的帮助)和非linkedin的用户(通过POST请求中的表单):

public function createUserAction($from_linkedin = false, $linkedin_data = null)
{
    $user = new User();
    if(!from_linkedin) {
        // User comes from the registration form
        $user = $post_data,
    } else {
        // User comes from linkedin OAuth
        $user = $linkedin_data;
    }
    $em->persist($user);
    $em->flush();
 }

我想让我的linkedin OAuth用户选择一个密码,这样他们将来就可以连接到linkedin或标准的电子邮件/密码表单。我也觉得这样更安全。

为了做到这一点,我创建了一个中介函数来向用户显示密码表单。此表单显示在linkedin调用之后和注册功能之前

protected function chosePasswordAction($linkedin_data)
{
    $form = createForm(new ChosePasswordType);
    if($method = POST) {
        $linkedin_data["password"] = $post_data["password"];
        return createUserAction(true, $linkedin_data);
    }
    return $this->renderView("chosePassword.html.twig", array(
        'form' => $form,
        'data' => $linkedin_data,
    ));
}

我的问题是什么:

表单显示得很好,但当我在POST请求中返回时出现了一个错误。$linkedin_data数组丢失,因此chosePassword()函数返回错误:

Controller "Bundle'Controller'UserController::chosePasswordAction()" 
requires that you provide a value for the "$linkedin_data" argument 
(because there is no default value or because there is a non optional 
argument after this one). 

我知道的唯一方法是在表单路由中添加$linkedin_data数组作为参数,但它一点也不安全。我怎样才能轻松通过而不冒风险?

既然我知道你在做什么,我会考虑在你第一次收到数据时将数据存储在php的$_SESSION中。不要再来回发送了。它不仅很黑客,而且很容易被篡改,尤其是如果你没有运行Linedin最可能所在的https。

快乐编码!