在身份验证中生成令牌

时间:2017-07-13 11:14:21

标签: symfony

我想用LexikJWTAuthenticationBundle生成令牌,但我有这个错误:

  

atchable致命错误:传递给Lexik \ Bundle \ JWTAuthenticationBundle \ Services \ JWTManager :: create()的参数1必须是Symfony \ Component \ Security \ Core \ User \ UserInterface的实例,MedBundle \ Entity \ Med的实例给出,在第53行的/var/www/html/authenti/src/MedBundle/Controller/ApiController.php中调用并定义

这是代码操作登录:

public function loginAction() {

            $em = $this->getDoctrine()->getManager();
            $request = $this->getRequest();
            if ($request->getMethod() == 'POST') {
                $username = $request->request->get('username');
                $password = $request->request->get('password');

             $test = $em->getRepository('MedBundle:Med')->findOneBy(array('username' => $username));

                if (!($test)) { var_dump('error'); } else{ 
                    $salt= $test->getSalt();
                    $pass = crypt($password,$salt);
                    if ( $pass === $test->getPassword() ) {
                    var_dump('success'); } 
                }

                $x = $this->get('lexik_jwt_authentication.jwt_manager')->create($test);
                var_dump($x);
     }     
                return $this->render('default/login.html.twig');

        }

如何解决此错误

0 个答案:

没有答案