我在使用 lexik JWT 捆綁包和 Symfony 6.0 時遇到了一些問題,因為我使用 NelmioApiDocBundle 大搖大擺。
問題是,在我決定應用從 lexik JWT 生成的授權令牌(承載令牌)之前,每個人都在大搖大擺地作業。但是一旦我通過/api/sign/in端點生成我的令牌并將其放入現場,突然所有端點都停止作業。就像 swagger 有這個加載影片,但是沒有請求來(用 xDebug 測驗過,也用 symfony profiler 測驗過)。
有趣的是,當我使用 Postman 并在那里應用令牌時,我立即得到了正確的回應。所以我不確定問題出在哪里或出了什么問題,但是從 Swagger 呼叫時,我可以看到 docker 除錯訊息說: PHP message: [debug] Authenticator does not support the request.
我將把我的配置放在下面。提前致謝。
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_ttl: 8640000
user_id_claim: id
user_identity_field: email
安全.yaml
security:
enable_authenticator_manager: true
password_hashers:
App\Entity\User:
algorithm: bcrypt
cost: 10
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/sign
stateless: true
provider: app_user_provider
json_login:
check_path: /api/sign/in
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
provider: app_user_provider
pattern: ^/api
stateless: true
jwt: ~
access_control:
- { path: ^/api/sign/, roles: PUBLIC_ACCESS }
- { path: ^/api/(doc|doc.json), roles: PUBLIC_ACCESS }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
nelmio_api_doc.yaml
nelmio_api_doc:
documentation:
servers:
- url: http://bp.project
info:
title: BP PROJECT
description: This is an awesome app!
version: 1.0.0
components:
securitySchemes:
Bearer:
type: http
scheme: bearer
bearerFormat: JWT
security:
Bearer: [ ]
areas: # to filter documented areas
path_patterns: # an array of regexps
- ^/api(?!/(doc|doc.json|docs.{_format}|{index}.{_format}|contexts/{shortName}.{_format})$) # Accepts routes under /api except ...
models: { use_jms: false }
uj5u.com熱心網友回復:
發現 api_platform swagger 和 nelmio 都以某種方式進行互動,因為我將其添加到 api_platform.yaml 中,并且標頭在 nelmio 中也可用,現在可以使用。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/425512.html
