0

I have Apache server and Postman to check if api url is working correctly and i have strange behaviour, meaning when i call with correct credentials http://localhost/xxx/web/app_dev.php/api/login_check on Postman, LexikJwtBundle is returning token so everything i working fine. But doing this in mozilla or Chrome i get 401 Bad Credentials, my security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        login:
            pattern:  ^/api/login
            stateless: true
            anonymous: true
            provider: fos_userbundle
            form_login:
                check_path:               /api/login_check
                success_handler:          lexik_jwt_authentication.handler.authentication_success
                failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                require_previous_session: false

        api:
            pattern:   ^/api
            stateless: true
            lexik_jwt: ~

        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                # csrf_provider: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
                csrf_token_generator: security.csrf.token_manager

            logout:       true
            anonymous:    true

request in mozilla:

Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Origin: http://sprawy.com
Connection: keep-alive

what could be wrong?

Viszman
  • 1,378
  • 1
  • 17
  • 47

2 Answers2

0

Your Symfony config looks fine.

set this header with your authentication request:

'Accept': 'application/json',
'Content-Type': 'application/json'
habibun
  • 1,552
  • 2
  • 14
  • 29
0

Angular didn't send appropiate header. Adding headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') when creating post call, resolved problem.

Viszman
  • 1,378
  • 1
  • 17
  • 47