相关疑难解决方法(0)

具有RESTful身份验证的Symfony2 App,使用FOSRestBundle和FOSUserBundle

我正在为我的JS驱动的应用程序制作REST API.

在登录期间,登录表单通过AJAX提交到/rest/login我的API的url .

  • 如果登录成功,则返回204
  • 如果失败,则返回401

虽然我已经为API和应用程序本身分离了防火墙,但它们共享相同的上下文,这应该意味着,当用户对API进行身份验证时,他也会针对应用程序进行身份验证.因此,当服务器返回204时,页面将重新加载,它应该将用户重定向到应用程序,因为他现在已登录.

我试图使用check_loginFOSUserBundle的预制页面并指向/rest/login那里.

login:
    path: /rest/login
    defaults:
        _controller: FOSUserBundle:Security:check
    methods: [ POST ]
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为它总是返回重定向,无论如何.我阅读了symfony的文档,找不到如何制作自定义check_login页面.我需要的是这样的事情

use Symfony\Component\Security\Core\Exception\AuthenticationException;
use FOS\RestBundle\Controller\Annotations\View;    

class SecurityController {

    /**
     * @View(statusCode=204)
     */
    public function loginAction($username, $password) {

        /* first I need to somehow authenticate user 
           using normal authentication, that I've set up */
        ...

        /* Then I need to return 204 or throw exception,
           based on result.
           This is done using FOSRestBundle and it's …
Run Code Online (Sandbox Code Playgroud)

php restful-authentication symfony fosuserbundle fosrestbundle

5
推荐指数
1
解决办法
1万
查看次数