我已经寻找了一段时间的解决方案。所有身份验证系统都已经就绪,我得到了令牌,但是当我使用它检索数据时,我得到了一个404 jwt。
我在这个项目上有紧急情况,一个帮助会对我有很大帮助。
这是我的security.yaml:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/login
stateless: true
json_login:
check_path: /api/login_check # or api_login_check as defined in config/routes.yaml
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
main:
lazy: true
provider: app_user_provider
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
- { path: ^/api/login, roles: PUBLIC_ACCESS }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }Pour声明du控制器:
api_login_check:
path: /api/login_check发布于 2022-07-14 00:59:03
您必须执行以下操作:转到/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)%'
token_extractors:
authorization_header:
enabled: true
prefix: Bearer
name: Authorization
cookie: // if you are using cookie
enabled: true
name: cookie_name // set the cookie name如果您正在使用httpClient;那么您可以授权:标题中的“承载者”.$token,如下所示;
$headers = [
'Authorization' => 'Bearer '.$token,
'Content-Type' => 'application/json',
];注意:确保您有jwt目录,其中有私钥和公钥。
https://stackoverflow.com/questions/72236185
复制相似问题