Symfony2 How do I authenticate a user on two different firewalls using two different methods?

I have two firewalls, one for my API calls (WSSE protected), one for my application. Both work well, but I need to authenticate the user on the api firewall and at the same time on the application firewall and I cannot do that.

My security.yml

firewalls:
    # Firewall for the api
    wsse_secured:
        pattern:   ^/api/.*
        wsse:
            nonce_dir: null
            lifetime: 300
            provider: fos_userbundle
        context: user

    # Firewall for the application
    main:
      pattern: /.*
      form_login:
            provider: fos_userbundle
            login_path:     fos_user_security_login
            check_path:     fos_user_security_check
            default_target_path: espace_perso
            always_use_default_target_path: false
            failure_path: fos_user_security_login
        logout:
            path: fos_user_security_logout
            target: fos_user_security_login
        oauth:
            resource_owners:
                facebook: "/login/check-facebook"
                linkedin: "/login/check-linkedin"
                google: "/login/check-google"
            login_path: fos_user_security_login
            oauth_user_provider:
                service: bg.oauth.user_provider
        anonymous: true
        context: user

      

I have already read another post ( this question , this one and this one ) and as you can see add context which does not work in my case.

I am trying to manually add the wsse header I need, or create a new WsseToken for my user with no success events.

I really need help for this problem, which should be common ...

+3


source to share


1 answer


As I understand it, you want to reuse an action in your API for user access. If not, please provide more details.

Your best bet would be to do another route for the same action, just under a different firewall.

Assuming you have:

<route id="api_form_validate" pattern="/api/validate-form">
    <default key="_controller">Bundle:ApiController:validateForm</default>
</route>

      



Add to

<route id="user_form_validate" pattern="/user/validate-form">
    <default key="_controller">Bundle:ApiController:validateForm</default>
</route>

      

And change the action of the form from api_form_validate

to user_form_validate

.

0


source







All Articles