jwt flexk未找到jwt认证



我一直在寻找解决方案一段时间了。所有的身份验证系统都就位了,我得到了我的令牌,但是当我用它来检索数据时,我得到一个404 jwt未找到。

我这个项目有紧急情况,有人来帮忙会帮我很多。

this is my security.yaml:

app_user_provider:
entity:
class: AppEntityUser
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 la declaration du controller:

api_login_check:
path: /api/login_check

您必须执行以下操作;进入/config/packages/lexk_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目录,在那里你有私钥和公钥。

相关内容

  • 没有找到相关文章

最新更新