Uwe
Uwe

Reputation: 295

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

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.

Upvotes: 0

Views: 1333

Answers (1)

Problematic
Problematic

Reputation: 17678

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.

To create routes under /api/*, you'll have to define the routing separately.

Upvotes: 1

Related Questions