symfony - Symfony 4 + API Plantform +LexikJWTAuthenticationBundle 坏凭证
问题描述
下午好。请我在 symfony 4 api 项目中使用 LexikJWTAuthenticationBundle。我正在将 UserProvider 用于 Doctrine。
在配置 Doctrine User Provider 之后,我已经安装并配置了 LexikJWTAuthenticationBundle。但是,当我尝试在 URL http://localhost:8000/api/login_check上使用 Postman 验证这个 JSON {"username":"ak", "password":"ak"} 我有这个错误:{"代码”:401,“消息”:“错误凭据”}。请参阅下面我的 Security.yaml 配置文件。我已经阅读论坛试图解决这个问题,但我还没有找到解决方案。你能帮我么?
security:
encoders:
App\Entity\Utilisateur:
algorithm: bcrypt
providers:
#in_memory: { memory: ~ }
our_db_provider:
entity:
class: App\Entity\Utilisateur
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/login
stateless: true
anonymous: true
json_login:
check_path: /api/login_check
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:
pattern: ^/
user_checker: App\Security\UtilisateurChecker
anonymous: true
provider: our_db_provider
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
解决方案
您在安装过程中是否遗漏了一项配置?我没有看到lexik:
lexik_jwt_authentication:
secret_key: '%kernel.project_dir%/config/jwt/private.pem' # required for token creation
public_key: '%kernel.project_dir%/config/jwt/public.pem' # required for token verification
pass_phrase: 'your_secret_passphrase' # required for token creation, usage of an environment variable is recommended
token_ttl: 3600
推荐阅读
- android - 在 Web 浏览器上访问我的网站时如何将用户重定向到我的应用程序
- dynamics-crm - 有人在使用 Selenium Web 驱动程序在 Dynamics 365 中进行自动化测试吗?
- python - 一个名字对应两个性别,重复数据框
- ios - iOS 14.0 Beta 中反复调用 DispatchQueue.main.asyncAfter
- c# - ASP Net Core 调用 Azure B2C 策略
- javascript - Converting Float to 2 Decimal Number in Javascript
- kotlin - 如何返回在 Kotlin 上进行操作的对象的值(类似于 Javascript 中的双点运算符)?
- python - 跨模块的 Matplotlib 导入问题
- firebase - FIrebase 云函数(删除 Firestore 文档)
- python - Python - 如何在字典中搜索值