如何同时在2个不同的symfony2防火墙上进行身份验证? [英] How to authenticate on 2 different symfony2 firewalls at the same time?

查看:74
本文介绍了如何同时在2个不同的symfony2防火墙上进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Symfony应用程序,其中包含两个区域,一个区域用于客户端从网页访问,另一个区域用于从AJAX和Web服务进行API调用.

I have a Symfony application with 2 areas, one for clients accessing from a web page an other for API calls from AJAX and web services.

该区域中的每个区域都单独受到防火墙的保护. WEB界面使用登录表单进行身份验证,API使用http_basic进行身份验证.

Each one of this areas is protected with a firewall on its own. The WEB interface is authenticated with a log in form and the API with http_basic.

两个防火墙都可以正常工作,但是当WEB界面对API界面进行AJAX调用时,浏览器会提示用户再次登录,即使该用户已经登录(通过登录表单)也是如此.这就是我要避免的.我希望同时对两个防火墙进行身份验证,以防止出现此提示.

Both firewalls work fine, but when the WEB interface makes an AJAX call to the API interface, then the browser prompts the user to log in again, even when he was already logged in (via log in form). This is what I want to avoid. I Would like that both firewalls were authenticated at the same time to prevent this prompt.

我看到了另一个与完全相同问题相同的问题.但是他们在两个防火墙上都使用了http_basic身份验证,因此,提出的解决方案不适用于我的情况:

I've seen another question with exactly the same problem. But they are using http_basic authentication on both firewalls, so, the solution proposed did't work on my case:

用一个登录表单对多个symfony2防火墙进行身份验证

我的security.yml

My security.yml

#....
firewalls:
    api:
        pattern:    ^/API
        context: primary_auth
        stateless:  true
        http_basic: 
            realm: "API: Please log in"

    web:
        pattern:    ^/
        context: primary_auth
        form_login:
            check_path: /login_check
            login_path: /login
            provider: fos_userbundle
        logout:
            path:   /logout
            target: /
        anonymous: ~

推荐答案

您可能想在这里查看:

You might want to look here: Authenticate multiple symfony2 firewalls with one login form there's solution to similar problem there

引用:

security:
# providers etc ...

    firewall:
        main:
            pattern: # ...
            provider: my_users
            http_basic: ~
            context: primary_auth  # new
        api:
            pattern: # ...
            provider: my_users
            http_basic: ~
            context: primary_auth  # new

这篇关于如何同时在2个不同的symfony2防火墙上进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆