1

I use api plateform, i have install LexikJWTAuthenticationBundle for my authentification.

my file security.yaml

security:
    encoders:
        App\Entity\User:
            algorithm: auto
    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        login:
            pattern: ^/api/login_check
            stateless: true
            anonymous: true
            provider: app_user_provider
            json_login:
                check_path: api_login_check
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
        api:
            pattern:   ^/api
            stateless: true
            anonymous: true
            provider: app_user_provider
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        classrooms:
            pattern:  ^/api/classrooms
            stateless: true
            anonymous: true
        schools:
            pattern:  ^/api/schools
            stateless: true
            anonymous: true
    access_control:
        - { path: ^/api/login_check, roles: PUBLIC_ACCESS }

routes.yaml

api_login_check:
    path: /api/login_check

When i call my endpoint api/login_check, i have response with user AND token jwt.

Is not a valid response : {}{}

It's my response with postman :

{
"username": "student@student.com",
"password": "password"
}{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2MzkwNzYwMjMsImV4cCI6MTYzOTA3OTYyMywicm9sZXMiOlsiUk9MRV9TVFVERU5UIiwiUk9MRV9VU0VSIl0sInVzZXJuYW1lIjoic3R1ZGVudEBzdHVkZW50LmNvbSIsInVzZXJfaWQiOjIsImVtYWlsIjoic3R1ZGVudEBzdHVkZW50LmNvbSIsInN0dWRlbnRfaWQiOjF9.rKHalyplwGq6gUr0MuXSHOOWhuRisHwbCUj8XXWxEOqmpnzU37W17SMc9kY_1t44lNdYpetU1mDKW0K9qOLyJ5rrRcvEMgUSiY6F0jG8LvwYbfHyncaztoKL4L9k_uUSuzOh0k8tb1L7cOmdNhYVelPcJ_4_Y0NDxu7Yd2iK9rjTsXYqwfo5xSMVyyRJR3WkSitVbB2WD1MPD9yA5Awb9YANtt_X3KPJJXTH9ma_dc7RVNWBxhnEBqg4v5oHRFiE8gAM0R4AyrrfoFYjt27AuEvQ5XFqFBMWTWG4iQYjiLjheNIUAnADRwiIsTlE6G7xLdZUrl_CJdVtZfYbBA0yQQ"}

when i have bad credentials:

{
"username": "student@student4.com",
"password": "password"
}{"code":401,"message":"Invalid credentials."}

I need response with correct format json (token only), i don't want user. I have this problem only on my prod server.

my docker containers:

CONTAINER ID   IMAGE                        COMMAND                  CREATED        STATUS        PORTS                                                    NAMES
dae2d40b1b85   docker-teacher-tool_php      "docker-php-entrypoi…"   12 hours ago   Up 12 hours   0.0.0.0:9000->9000/tcp, :::9000->9000/tcp                teacher-tool-php
adb596651e38   nginx:stable-alpine          "/docker-entrypoint.…"   12 hours ago   Up 12 hours   0.0.0.0:8000->80/tcp, :::8000->80/tcp                    docker-teacher-tool_nginx_1
9ca8840fdbd3   phpmyadmin                   "/docker-entrypoint.…"   12 hours ago   Up 12 hours   0.0.0.0:8080->80/tcp, :::8080->80/tcp                    docker-teacher-tool_phpmyadmin_1
7d50a994cfa2   docker-teacher-tool_nodejs   "docker-entrypoint.s…"   12 hours ago   Up 12 hours   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp                docker-teacher-tool_nodejs_1
41ba41f25dbf   dunglas/mercure:v0.10.4      "/mercure"               12 hours ago   Up 12 hours   443/tcp, 0.0.0.0:3001->80/tcp, :::3001->80/tcp           docker-teacher-tool_mercure_1
d30a709aef60   mysql:8.0                    "docker-entrypoint.s…"   12 hours ago   Up 12 hours   33060/tcp, 0.0.0.0:49157->3306/tcp, :::49157->3306/tcp   docker-teacher-tool_database_1

Edit security.yaml

security:
    encoders:
        App\Entity\User:
            algorithm: auto
    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        login:
            pattern: ^/api/login
            stateless: true
            anonymous: true
            provider: app_user_provider
            json_login:
                check_path: api_login_check
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
        api:
            pattern:   ^/api
            stateless: true
            anonymous: true
            provider: app_user_provider
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
        # dev:
        #     pattern: ^/(_(profiler|wdt)|css|images|js)/
        #     security: false
        classrooms:
            pattern:  ^/api/classrooms
            stateless: true
            anonymous: true
        schools:
            pattern:  ^/api/schools
            stateless: true
            anonymous: true
    access_control:
        # - { path: ^/api/login_check, roles: PUBLIC_ACCESS }

in my var/log/nginx/project_error.log

PHP message: [debug] SELECT t0.id AS id_1, t0.email AS email_2, t0.roles AS roles_3, t0.password AS password_4, t0.first_name AS first_name_5, t0.last_name AS last_name_6, t0.created_at AS created_at_7, t8.id AS id_9, t8.user_id AS user_id_10, t11.id AS id_12, t11.user_id AS user_id_13 FROM user t0 LEFT JOIN teacher t8 ON t8.user_id = t0.id LEFT JOIN student t11 ON t11.user_id = t0.id WHERE t0.email = ? LIMIT 1
PHP message: [debug] SELECT t0.id AS id_1, t0.type AS type_2 FROM role t0 INNER JOIN role_user ON t0.id = role_user.role_id WHERE role_user.user_id = ?
PHP message: [info] User has been authenticated successfully.
PHP message: [debug] Notified event "lexik_jwt_authentication.on_jwt_created" to listener "App\EventSubscriber\JWTSubscriber::onLexikJwtAuthenticationOnJwtCreated".
PHP message: [debug] Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
PHP message: [debug] Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ValidateRequestListener::onKernelRequest".
PHP message: [debug] Notified event "kernel.request" to listener "Nelmio\CorsBundle\EventListener\CorsListener::onKernelRequest".
PHP message: [debug] Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\SessionListener::onKernelRequest".
PHP message: [debug] Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::setDefaultLocale".
PHP message: [debug] Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
PHP message: [debug] Notified event "kernel.request" to listener "ApiPlatform\Core\EventListener\QueryParameterValidateListener::onKernelRequest".
PHP message: [debug] Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKerne
2021/12/09 20:25:10 [error] 31#31: *109 FastCGI sent in stderr: "PHP message: [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /"" at /var/www/symfony_docker/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136" while reading response header from upstream, client: 88.9.119.217, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.6:9000", host: "146.59.237.234:8000"

my nginx config:

server {
    client_max_body_size 500M;

    listen 80;
    index index.php;
    server_name localhost;
    root /var/www/symfony_docker/public;
    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\\.php(/|$) {
        fastcgi_pass php:9000;
        fastcgi_split_path_info ^(.+\\.php)(/.*)$;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;

        internal;
    }

    location ~ \\.php$ {
        return 404;
    }

}
ThomasM
  • 67
  • 1
  • 6

1 Answers1

0
login:
    pattern: ^/api/login_check
    ...
    json_login:
       check_path: /api/login_check

It doesn't feel right that these two paths are the same. Are you sure this is ok?

Michal Trojanowski
  • 10,641
  • 2
  • 22
  • 41