csrf_protection - 没有能够加载的扩展
csrf_protection - no extension able to load
我是 API 平台的新手,正在尝试使用 FOSUserBundle 进行 JWT 身份验证。
我一步步跟着https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
教程和第 5 步之后,当我尝试重新 运行 第 1 步时,我得到错误:
没有扩展能够加载 "csrf_protection" 的配置(在 E:\rest-api\app/config\config.yml)。查找命名空间 "csrf_protection", f
回合 "framework", ...
我在尝试更新方案时也遇到了同样的错误。有什么帮助吗??
这是我的security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
# pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
Scsrf_token_generator: security.csrf.token_manager
#csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
这是我添加到config.yml
api_platform:
http_cache:
invalidation:
enabled: true
#varnish_urls: '%varnish_urls%'
max_age: 0
shared_max_age: 3600
vary: ['Content-Type', 'Authorization']
public: true
swagger:
api_keys:
- { name: 'Authorization', type: 'header'}
enable_fos_user: true
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\AuthUser
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
csrf_protection:
enabled: false
AppKernel.php
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
new AppBundle\AppBundle(),
new Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
];
有 suggestuion/help 吗?
从您的 config.yml
中删除此 csrf_protection 配置
csrf_protection:
enabled: false
我认为您的配置中有一个错误的配置,请阅读此文档:https://api-platform.com/docs/core/fosuser-bundle/他们有一个很好的 JWT 身份验证与 api 平台集成的教程。祝你好运!
我是 API 平台的新手,正在尝试使用 FOSUserBundle 进行 JWT 身份验证。
我一步步跟着https://symfony.com/doc/master/bundles/FOSUserBundle/index.html 教程和第 5 步之后,当我尝试重新 运行 第 1 步时,我得到错误:
没有扩展能够加载 "csrf_protection" 的配置(在 E:\rest-api\app/config\config.yml)。查找命名空间 "csrf_protection", f 回合 "framework", ...
我在尝试更新方案时也遇到了同样的错误。有什么帮助吗??
这是我的security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
# pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
Scsrf_token_generator: security.csrf.token_manager
#csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
这是我添加到config.yml
api_platform:
http_cache:
invalidation:
enabled: true
#varnish_urls: '%varnish_urls%'
max_age: 0
shared_max_age: 3600
vary: ['Content-Type', 'Authorization']
public: true
swagger:
api_keys:
- { name: 'Authorization', type: 'header'}
enable_fos_user: true
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\AuthUser
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
csrf_protection:
enabled: false
AppKernel.php
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
new AppBundle\AppBundle(),
new Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
];
有 suggestuion/help 吗?
从您的 config.yml
中删除此 csrf_protection 配置csrf_protection:
enabled: false
我认为您的配置中有一个错误的配置,请阅读此文档:https://api-platform.com/docs/core/fosuser-bundle/他们有一个很好的 JWT 身份验证与 api 平台集成的教程。祝你好运!