Home > Blockchain >  How to Restrict a post Request with basic auth in symfony 4.4
How to Restrict a post Request with basic auth in symfony 4.4

Time:03-05

I need to protect a POST request with basic auth like http://host/import/myfile in Symfony 4.4

In security.yaml, I tried this but It doesn't work

  providers:
   authorized_users:
         http_basic:
            - identifier: '%env(HTTP_BASIC_AUTH_USERNAME)%'
            - password: '%env(HTTP_BASIC_AUTH_PASSWORD)%'
   firewalls:
         secured_area:
            methods: [POST]
            pattern: ^/import/myfile
            provider: authorized_users

CodePudding user response:

Here is the answer, hope that will help !

    providers:
        authorized_users:
            memory:
                users:
                    "%env(HTTP_BASIC_AUTH_USERNAME)%":
                        password: '%env(HTTP_BASIC_AUTH_PASSWORD)%'
                        
     firewalls:
        secured_area:
            pattern: ^/import/myfile
            stateless: true
            http_basic:
                provider: authorized_users

  • Related