Я думаю, у вас проблема с файлом config/routes.yaml
. Мой конфиг выглядит так:
api_login_check:
path: /api/users/login
methods: [POST]
Для вас может потребоваться поставить как path: /authentication
На всякий случай я напишу здесь полную конфигурацию JWT моего проекта.
config / packages / lexik_jwt_authentication.yaml:
lexik_jwt_authentication:
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
user_identity_field: phone <-- for auth user (username/login)
token_ttl: 3600
config / packages / security.yaml:
security:
encoders:
App\Entity\User:
algorithm: auto
providers:
app_user_provider:
entity:
class: App\Entity\User
property: phone <-- it's my property that i use as username
firewalls:
login:
pattern: ^/api/
stateless: true
anonymous: true
provider: app_user_provider
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
json_login:
check_path: ~
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
src / Entity / User. php
<?php
declare(strict_types=1);
namespace App\Entity;
// use ...
/**
* @ApiResource(
* security="is_granted('ROLE_USER')",
* itemOperations={
* "get" = {"security" = "is_granted('ROLE_USER') and object == user"},
* // other operations ...
* },
* collectionOperations={
* "get",
* "post" = {
* "security" = "is_granted('IS_AUTHENTICATED_ANONYMOUSLY')"
* },
* "login" = {
* "security" = "is_granted('IS_AUTHENTICATED_ANONYMOUSLY')",
* "route_name" = "api_login_check",
* "method" = "POST",
* "openapi_context" = {
* "summary" = "Login method",
* "requestBody" = {
* "description" = "Get token",
* "content" = {
* "application/json" = {
* "schema" = {
* "type" = "object",
* "required" = {
* "username",
* "password"
* },
* "properties" = {
* "username" = {
* "type" = "string"
* },
* "password" = {
* "type" = "string"
* }
* }
* }
* }
* }
* }
* }
* },
* // other operations ...
* },
* // ...
* )
* // ...
*/
class User implements UserInterface
{
// ...
}
PS Я использую Symfony V5, но я думаю, что ничем не отличается