json身份验证如何使用symfony



我不知道是什么阻塞了。我一直在关注symfony文档。

/security.yaml

security:
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers:
SymfonyComponentSecurityCoreUserPasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
# users_in_memory: { memory: null }
app_user_provider:
entity:
class: AppEntityUser
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
#lazy: true
provider: app_user_provider
json_login:
# api_login is a route we will create below
check_path: api_login
#username_path: email
#password_path: password
#username_path: security.credentials.email
#password_path: security.credentials.password

/控制器/ApiLoginController.php

#[Route('/login', name: 'app_api_login', methods: 'POST')]
public function index(#[CurrentUser] ?User $user): Response
{
dd($user);
}

我在头的请求中设置了Content-Type application/json,并在主体中放入json{"username": "toto@toto.com","password": "root"}和我向邮递员发出了请求。

我总是得到null作为响应。。。欢迎您的帮助

好的,我更改

check_path: api_login

通过

check_path: app_api_login

check_path必须与名称相同:"app_api_login"天哪。。。。

最新更新