我大约3天处于糟糕状态,我正在尝试制作一个简单的auth&register应用程序,但是在使用我正在生成的令牌时,我总是遇到这500个错误:
无法通过给定配置验证给定的JWT。如果自上次验证后“lexik_jwt_authentication.encoder”加密选项已更改,请更新令牌。如果问题仍然存在,请验证配置的密钥/密码是否有效。
我想知道实际上什么不好,这是我的配置:在parameters.yml
jwt_public_key_path: '%kernel.root_dir%/../var/jwt/public.pem'
jwt_private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
jwt_key_pass_phrase: pass
jwt_token_ttl: 3600
config.yml
lexik_jwt_authentication:
private_key_path: '%jwt_private_key_path%'
public_key_path: '%jwt_public_key_path%'
pass_phrase: 'pass'
token_ttl: '36000'
token_extractors:
authorization_header: # look for a token as Authorization Header
enabled: true
prefix: Bearer
name: Authorization
cookie: # check token in a cookie
enabled: false
name: BEARER
query_parameter: # check token in query string parameter
enabled: false
name: bearer
security.yml```防火墙:main:pattern:^ / anonymous:true stateless:true
logout: true
anonymous: true
guard:
authenticators:
- 'token_authenticator'
login:
pattern: ^/api/login
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
username_parameter: username
password_parameter: password
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
```
我在v2.4 / w SF 3.3@dev上,似乎某些版本之间的某些东西崩溃了。尽管如此,即使在更新密钥/重新生成令牌之后,暂时没有任何好处,我总是会出现这个错误。
我正在通过邮递员执行我的请求,令牌正确生成并且问题不是来自标题中的授权参数,我已经尝试了很多东西,看看它是不是我的错,似乎不是在这种情况下,
任何帮助/提示都非常感谢:)
您应该使用以下命令重新生成公钥和私钥:
openssl genrsa -out config/jwt/private.pem -aes256 4096
openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem
并确保密码为'pass'以使配置生效。