我正在使用LexikJWTAuthenticationBundle,我可以通过在/ api / login_check上执行curl来生成令牌,但是当我调用任何其他api时,它都有一个空用户。
var_dump($tokenStorage->getToken()); die();
响应
对象(Lexik \ Bundle \ JWTAuthenticationBundle \ Security \ Authentication \ Token \ JWTUserToken)#333 (6){ [“ rawToken”:受保护] => 串(824) “eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1NDA1NDc0NzAsImV4cCI6MTU0MDU1MTA3MCwicm9sZXMiOlsiUk9MRV9VU0VSIl0sInVzZXJuYW1lIjoiam9ubnkxIn0.Ja0V - MHZ-JaLJPcNaEhPrCV9nRKURCjsiZsCEDwUQ2rlwxejPniAe5GjXT3vaT6s8k6CsR725Nh7n_A_JhU1-egP99WkZCi99Y82Wtoqciwqt83M_L1yvrAonugDsx99daP8AVZpAsKXHskuyJ0DrPzdNljiGgSx0s15B0NRi0HGQh-bWV1IRJvHCBPOm2bIh840YDQ2ilfOaNFnS_ZTd0aRcaOcUk_XrSWNgnLyTy31aJvAKfCaUM_g1pRVL8DzuHsWIMNXMT3wcilInANIpGLSypFzrYr75mzJ3JEuVwnjllJITFFL2eayuBIjyL4bxkzAGmoGRdf55T-uCG7Jbcc-iw2BiHcSVbaHWuotG5Mt3UFBhvysZ2d94Ox873B7eJZJhMqjvTaSubgHQs0nqkwqVvCd-5IEl1pdFP8e_xkkSLPX4Wmx-DgArO_CIY8tBFKKTij0EpCDfMsHrgJOKzhPTwDnpuMNxAhVM9vPe9Tqz1ZW2Ov_lNKZkOaCVNGIDmpQQHuuKOw7_BedrbV5sZN6iNwiMqlusGfVS0x0Tz4he0uUw7A2GtaFLXgt4HyHYYa5U4pNKHkltPJgQwBDoCa5h1If5gZn0xYZWFhpbPNZbTtlT17UL1cbS9KTRiZ5vK83mW59jLjPWnUMq43O_RNXw2s8dQgzkL2mdwxrbk” [“ providerKey”:受保护] => 空值 [“用户”:“ Symfony \ Component \ Security \ Core \ Authentication \ Token \ AbstractToken”:专用] => 空值 [“角色”:“ Symfony \ Component \ Security \ Core \ Authentication \ Token \ AbstractToken”:专用] => 数组(0){ } [“已认证”:“ Symfony \ Component \ Security \ Core \ Authentication \ Token \ AbstractToken”:专用] => 布尔值(true) [“属性”:“ Symfony \ Component \ Security \ Core \ Authentication \ Token \ AbstractToken”:专用] => 数组(0){ } }
Security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface:
algorithm: bcrypt
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/login
provider: fos_userbundle
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
provider: fos_userbundle
require_previous_session: false
username_parameter: username
password_parameter: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/api
stateless: true
provider: fos_userbundle
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
lexik_jwt:
authorization_header:
enabled: true
prefix: Bearer
query_parameter:
enabled: true
name: bearer
throw_exceptions: false
create_entry_point: true
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
有人知道是什么问题吗?