ApiPlatform JWT – Unable to find the controller for path "/authentication_token". The route is wrongly configured

I use Symfony5 and React, with docker.

Both container are on different docker-compose but on the same newtork, so they can see and ping each other.

Now, I’ve installed JWT as the api paltform doc demands: https://api-platform.com/docs/core/jwt/

My security.yml:

security:
    encoders:
        AppEntityUser:
            algorithm: auto
    providers:
        app_user_provider:
            entity:
                class: AppEntityUser
                property: email
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            stateless: true
            anonymous: true
            lazy: true
            provider: app_user_provider
            json_login:
                check_path: /authentication_token
                username_path: email
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
    access_control:
        - { path: ^/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/docs, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: IS_AUTHENTICATED_FULLY }

My routes.yml, in the doc, I should only set [‘POST’], but doing so generate an error saying: No route found for "GET /authentication_token": Method Not Allowed (Allow: POST) so I fixed it by adding ‘GET’

authentication_token:
    path: /authentication_token
    methods: ['POST', 'GET']

If I try to call /authenticate_token from the front:

const response = await fetch('https://localhost:8443/authentication_token', {
                credentials: 'include',
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: data
            })

Then I get:

Unable to find the controller for path "/authentication_token". The route is wrongly configured.

But if I send the same request with curl :
curl -k -X POST -H "Content-Type: application/json" https://localhost:8443/authentication_token -d '{"email":"[email protected]", "password":"user"}'

I receive the token as supposed to.

I precise that the route is also working on postman.

Does anyone know if it’s an issue with the request or on backend side ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *