symfony2 API 身份验证和路由
我按照创建自定义身份验证提供程序的说明进行操作: 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
现在我在带有路由的控制器中有一些操作。例如:
ExampleController 与 listAction
路由:
example_list:
pattern: /example/list
defaults: { ... }
我是否必须将所有路由复制到 example_api_list?因为 api/example/list 不起作用(找不到 /api/example/list 的路由)。我认为防火墙的模式是所有已定义路由的前缀。
I followed the instructions for creating a custom authentication provider: 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. e.g:
ExampleController with listAction
routing:
example_list:
pattern: /example/list
defaults: { ... }
Do I have to copy all the routes to example_api_list? Because api/example/list didnt work (no route found for /api/example/list). I thought the pattern from the firewall is a prefix for all defined routes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
防火墙不是前缀,而是与传入路由匹配的正则表达式。在这种情况下,以
/api
开头的任何内容都将由您的wsse_protection
防火墙匹配,而所有未通过的内容都将由您的main
防火墙匹配。要在 /api/* 下创建路由,您必须单独定义路由。
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 yourwsse_protection
firewall, and everything that falls through will be matched by yourmain
firewall.To create routes under /api/*, you'll have to define the routing separately.