【问题标题】:How to use multiple firewalls in symfony 2.8 for same pattern?如何在 symfony 2.8 中为相同的模式使用多个防火墙?
【发布时间】:2018-01-16 15:09:40
【问题描述】:

我有一个 symfony 2.8 应用程序,将用作 REST API 后端

我想为所有匹配 ^/api 的端点添加安全性 我希望能够为 ^/api

使用 3 种不同的身份验证方法

我正在使用 uma/psr7-hmac-bundle、friendsofsymfony/oauth-server-bundle、APIKey 身份验证。

我定义了 3 个不同的防火墙,如果我删除其他两个防火墙,每个防火墙都可以正常工作。

firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        oauth_token:
            pattern: ^/oauth/v2/token
            security: false

        oauth_authorize:
            pattern: ^/oauth/v2/auth
            security: false

        api_key:
            pattern: ^/api
            stateless: true
            simple_preauth:
                authenticator: api_key_authenticator
            provider: api_key_user_provider

        oauth_api:
            pattern: ^/api
            stateless: true 
            fos_oauth: true
            provider: oauth_user

        hmac_api:
            pattern: ^/api
            stateless: true  
            hmac: 
                apikey_header: 'X-Custom-Header-Key'
            provider: hmac_user 

如何同时使用所有 3 个防火墙(链接它们)? (hmac_api, oauth_api, api_key)

我研究了 Guards,但我不确定如何为 HMAC 和 oAuth 定义/实现身份验证器。

我查看了防火墙上下文,但因为它是无状态的,所以它不起作用。

基本上,我怎样才能为相同的模式链接多个防火墙?或者考虑到我正在使用诸如friendsofsymfony/oauth-server-bundle、uma/psr7-hmac-bundle之类的第三方捆绑包,我该如何定义一个具有3个不同身份验证器的防火墙?

【问题讨论】:

    标签: symfony oauth hmac api-key symfony-security


    【解决方案1】:

    使用

    guard:
        authenticators:
    

    用于为您的防火墙链接身份验证器 这就是我的应用程序中的内容

    api:
                pattern:   ^/api         
                guard:
                    authenticators:
                        - bor.api_bundle.session_authenticator
                        - lexik_jwt_authentication.jwt_token_authenticator
                        - sergei_k_security.token_authenticator
                    entry_point: lexik_jwt_authentication.jwt_token_authenticator
    

    文档 - http://symfony.com/doc/current/security/multiple_guard_authenticators.html

    【讨论】:

    • 您如何定义 uma/psr7-hmac-bundle、friendsofsymfony/oauth-server-bundle 的身份验证器?
    猜你喜欢
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多