我在登录时遇到问题。当我输入用户凭据并按登录按钮时,它将创建一个用户令牌并重定向到主页,但是当请求获取主页时,用户令牌不存在... 这是dev.log文件中的数据
request.INFO: Matched route "login_check". {"route":"login_check","route_parameters":{"_route":"login_check","_controller":"App\\Controller\\Auth\\LoginController::login"},"request_uri":"http://localhost:8082/login","method":"POST"} []
security.INFO: User has been authenticated successfully. {"username":"jac@jack.com"} []
security.DEBUG: Fallback to the default authentication success handler. [] []
security.DEBUG: Clearing remember-me cookie. {"name":"REMEMBERME"} []
security.DEBUG: Remember-me was requested; setting cookie. [] []
security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
request.INFO: Matched route "main". {"route":"main","route_parameters":{"_route":"main","_controller":"App\\Controller\\MainController::index"},"request_uri":"http://localhost:8082/","method":"GET"} []
security.DEBUG: Read existing security token from the session. {"key":"_security_main","token_class":"Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken"} []
security.WARNING: Username could not be found in the selected user provider. {"username":null,"provider":"App\\Security\\UserProvider"} []
security.DEBUG: Remember-me cookie detected. [] []
security.INFO: User for remember-me cookie not found. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException(code: 0): Username \"jac@jack.com\" does not exist. at /opt/aicty/src/Security/UserProvider.php:52)"} []
security.DEBUG: Clearing remember-me cookie. {"name":"REMEMBERME"} []
security.INFO: Populated the TokenStorage with an anonymous Token. [] []
security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at /opt/aicty/vendor/symfony/security/Http/Firewall/AccessListener.php:68)"} []
security.DEBUG: Calling Authentication entry point. [] []
request.INFO: Matched route "show_login". {"route":"show_login","route_parameters":{"_route":"show_login","_controller":"App\\Controller\\Auth\\LoginController::showLogin"},"request_uri":"http://localhost:8082/login","method":"GET"} []
security.INFO: Populated the TokenStorage with an anonymous Token. [] []
request.INFO: Matched route "_wdt". {"route":"_wdt","route_parameters":{"_route":"_wdt","_controller":"web_profiler.controller.profiler::toolbarAction","token":"e96cb7"},"request_uri":"http://localhost:8082/_wdt/e96cb7","method":"GET"} []
这是我的安全Yaml conf。我从symfony文档中获得了User类和UserProvider类。
security:
encoders:
App\Entity\User:
algorithm: bcrypt
cost: 12
providers:
japi:
id: App\Security\UserProvider
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
provider: japi
simple_form:
login_path: show_login
check_path: login_check
username_parameter: email
password_parameter: password
authenticator: App\Security\Authenticator
remember_me: true
provider: japi
答案 0 :(得分:0)
您使用https://github.com/lexik/LexikJWTAuthenticationBundle吗?
配置非常简单:
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
webservice:
id: App\Security\UserProvider
encoders:
App\Entity\User:
algorithm: bcrypt
cost: 12
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/login
stateless: true
anonymous: true
json_login:
check_path: /login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
答案 1 :(得分:0)
就我而言, 我更改了用户实体,却忘记了在sql中生成或更新表,您可以使用以下命令来更新或生成表。
php bin/console doctrine:schema:update --force
或
php bin/console make:migration
php bin/console doctrine:migrations:migrate