我目前正在编程一个网站使用Symfony版本6.2和API Platform,此外还有数据库中的MongoDB和Docker上的工作环境.
我正在try 添加通过JWT(LexikJWTAuthenticationBundle)连接的功能,我能够成功登录并获得令牌,但当我try 使用令牌访问其余页面时,响应总是如下所示:
{
"code": 401,
"message": "JWT Token not found"
}
我在搜索引擎中搜索了以下问题的原因,提供了许多解决方案(尽管不幸的是,在与最新版本的symfony相关的所有内容中都没有这些解决方案),最明显的是修改了环境并添加了以下代码:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
老实说,我不知道如何在Docker环境中更改这个命令,但当我在索引页面上使用以下代码判断令牌是否正在发送时,我得到了正确的答案,并且令牌正在发送
$token = getallheaders()['Authorization'];
print_r($token);
exit;
我在Docker上的vhost.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/project/public
DirectoryIndex /index.php
<Directory /var/www/project/public>
AllowOverride None
Order Allow,Deny
Allow from All
FallbackResource /index.php
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
# optionally disable the fallback resource for the asset directories
# which will allow Apache to return a 404 error when files are
# not found instead of passing the request to Symfony
<Directory /var/www/project/public/bundles>
FallbackResource disabled
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
# optionally set the value of the environment variables used in the application
#SetEnv APP_ENV prod
#SetEnv APP_SECRET <app-secret-id>
#SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
</VirtualHost>
我查阅了使用过的Bundle 包(LexikJWTAuthenticationBundle)的官方文档,但不幸的是,当我执行下一步时:
# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
# ...
api_platform:
check_path: /api/login_check
我得到以下错误:
Unrecognized option "api_platform" under "lexik_jwt_authentication". Available options are "additional_public_keys", "allow_no_expiration", "clock_skew", "encoder", "pass_phrase", "private_key_path", "public_key", "public_key_path", "remove_token_from_body_when_cookies_used", "secret_key", "set_cookies", "token_extractors", "token_ttl", "user_id_claim", "user_identity_field".
有什么解决办法吗?