3 回答

TA貢獻1777條經驗 獲得超3個贊
也許您忘記在防火墻部分或登錄參數(電子郵件作為用戶名)中配置登錄防火墻..
檢查這個
1配置/包/security.yaml
? ? firewalls:
? ? ? ? login:
? ? ? ? ? ? pattern:? ^/api/login
? ? ? ? ? ? stateless: true
? ? ? ? ? ? anonymous: true
? ? ? ? ? ? form_login:
? ? ? ? ? ? ? ? check_path:? ? ? ? ? ? ? ?/api/login_check
? ? ? ? ? ? ? ? username_parameter: email
? ? ? ? ? ? ? ? password_parameter: password
? ? ? ? ? ? ? ? success_handler:? ? ? ? ? lexik_jwt_authentication.handler.authentication_success
? ? ? ? ? ? ? ? failure_handler:? ? ? ? ? lexik_jwt_authentication.handler.authentication_failure
? ? ? ? ? ? ? ? require_previous_session: false
? ? ? ? api:
? ? ? ? ? ? pattern:? ?^/api
? ? ? ? ? ? stateless: true
? ? ? ? ? ? guard:
? ? ? ? ? ? ? ?authenticators:
? ? ? ? ? ? ? ? ? ?- lexik_jwt_authentication.jwt_token_authenticator
? ? ? ? access_control:
? ? ? ? ? ? - { path: ^/api/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
? ? ? ? ? ? - { path: ^/api/, role: IS_AUTHENTICATED_FULLY }
2配置/routes.yaml
api_login_check:
? ? path: /api/login_check
3用curl測試一下
X POST -H "Content-Type: application/json" http://localhost/api/login_check -d '{"email":"[email protected]","password":"pass"}'

TA貢獻1807條經驗 獲得超9個贊
您不允許匿名訪問任何防火墻。您應該將匿名選項添加到您的主防火墻中。
main:
pattern: ^/
stateless: true
anonymous: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
provider: doctrine_provider

TA貢獻2037條經驗 獲得超6個贊
我發現此升級存在問題,但我有解決方案。
在 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: '%env(JWT_TTL)%'
token_extractors:
authorization_header:
enabled: true
prefix: '%env(JWT_TOKEN_PREFIX)%'
name: Authorization
user_identity_field: email
- 3 回答
- 0 關注
- 149 瀏覽
添加回答
舉報