2017-09-26 54 views
0

此問題已在此處提問stackoverflow。我正在實施symfony的FOSUserBundle。我已經配置好了一切爲這些問題提供瞭解決方案,但我仍然收到此錯誤,當我運行Symfony在「security.firewalls.main」下無法識別的選項「csrf_token_generator」

php app/console doctrine:schema:update --force 

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] 
    Unrecognized option "csrf_token_generator" under "security.firewalls.main" 

security.yml

security: 

encoders: 
    FOS\UserBundle\Model\UserInterface: bcrypt 
role_hierarchy: 
    ROLE_ADMIN:  ROLE_USER  
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded 
providers: 
    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: 
     form_login: 
      login_path: login 
      check_path: login 
     pattern: ^/ 
     http_basic: ~ 
     provider: fos_userbundle 
     csrf_token_generator: security.csrf.token_manager 
     # activate different ways to authenticate 

     # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate 
     #http_basic: ~ 

     # https://symfony.com/doc/current/security/form_login_setup.html 
     #form_login: ~ 
     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

framework: 
#esi: ~ 
#translator: { fallbacks: ['%locale%'] } 
translator: ~ 
secret: '%secret%' 
router: 
    resource: '%kernel.root_dir%/config/routing.yml' 
    strict_requirements: ~ 
form: ~ 
csrf_protection: 
    enabled: true 
validation: { enable_annotations: true } 
#serializer: { enable_annotations: true } 
templating: 
    engines: ['twig'] 
default_locale: '%locale%' 
trusted_hosts: ~ 
trusted_proxies: ~ 
session: 
    # handler_id set to null will use default session handler from php.ini 
    handler_id: ~ 
fragments: ~ 
http_method_override: true 

AppKernel.php

$bundles = array(
     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 AppBundle\AppBundle(), 
     new FOS\UserBundle\FOSUserBundle(), 
    ); 

有什麼我錯過了。任何幫助深表感謝。

回答

1

物業csrf_token_generator: security.csrf.token_manager應放在以下form_login

firewalls: 
    main: 
     form_login: 
      login_path: login 
      check_path: login 
      csrf_token_generator: security.csrf.token_manager 
+0

我已經更新了我的代碼,但現在我得到這個錯誤----「[Symfony的\分量\ CONFIG \定義\異常\ InvalidConfigurationException] 路徑「fos_user.from_email.address」不能包含空值,但爲空。「 – Aamir

+0

我從電子郵件地址問題中發現了這個問題。謝謝。 – Aamir

+0

將令牌管理器指定爲令牌生成器似乎並不奇怪嗎?如原始錯誤消息所示,csrf_token_generator應該是csrf_token_manager。基本上是一個錯字。 – Cerad

相關問題