简体   繁体   English

symfony2 API身份验证和路由

[英]symfony2 API authentication and routing

I followed the instructions for creating a custom authentication provider: http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html 我按照说明创建了一个自定义身份验证提供程序: http : //symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

app/config/security : 应用程序/配置/安全性

firewalls:
    wsse_protection:
        pattern: ^/api/.*
        wsse: true
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
        logout:       true
        anonymous:    true

Now I have some Actions in the Controllers with routes. 现在,我在带有路由的控制器中有一些操作。 eg: 例如:

ExampleController with listAction 带listAction的ExampleController

routing : 路由

example_list:
    pattern: /example/list
    defaults: { ... }

Do I have to copy all the routes to example_api_list? 我是否必须将所有路由复制到example_api_list? Because api/example/list didnt work (no route found for /api/example/list). 因为api / example / list无效(找不到/ api / example / list的路由)。 I thought the pattern from the firewall is a prefix for all defined routes. 我认为来自防火墙的模式是所有已定义路由的前缀。

The firewall isn't a prefix, it's a regular expression that matches against incoming routes. 防火墙不是前缀,而是与传入路由匹配的正则表达式。 In this case, anything starting with /api will be matched by your wsse_protection firewall, and everything that falls through will be matched by your main firewall. 在这种情况下, wsse_protection防火墙将匹配以/api wsse_protection所有内容,而main防火墙将匹配所有wsse_protection内容。

To create routes under /api/*, you'll have to define the routing separately. 要在/ api / *下创建路由,您必须单独定义路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM