编程语言
首页 > 编程语言> > php-必须配置路径“ security.firewalls.main.remember_me”处的子节点“ secret”

php-必须配置路径“ security.firewalls.main.remember_me”处的子节点“ secret”

作者:互联网

我在SO上看到过类似的问题,但是找不到我的问题的答案. Symfony2 documentation说明了如何实现“记住我”功能.

这是我的parameters.yml:

# This file is auto-generated during the composer install parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null

# A secret key that's used to generate certain security-related tokens
secret: DSHJLREYQF98321BN23B1100F

这是我的security.yml:

security:

    providers:
        in_memory:
            memory:
                users:
                    user1:
                        password: user1
                        roles: 'ROLE_USER'
                    user2:
                        password: user2
                        roles: 'ROLE_USER'
                    admin:
                        password: admin
                        roles: 'ROLE_ADMIN'

    firewalls:
        default:
            remember_me:
                key:      "%secret%"
                lifetime: 604800 # 1 week in seconds
                path:     /

        # Need to create route in routing.yml, but no need in a controller
        secured_area:
            logout:
                path:   /logout
                target: /

        # disables authentication for js,css, images, etc...
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        # fallback -> types of authentication
        main:
            anonymous: ~
            form_login:
                login_path: homepage
                check_path: login_check
                default_target_path: homepage
                failure_path: homepage
            remember_me:
                key:      "%secret%"
                lifetime: 604800 # 1 week in seconds
                path:     /

    encoders:
        # algorithm to encode passwords
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        # admin is user too
        ROLE_ADMIN:       ROLE_USER

    access_control:
        # require ROLE_ADMIN for admin page 
        - { path: ^/restricted/admin, roles: ROLE_ADMIN }
        # require ROLE_USER for user pages
        - { path: ^/restricted/user, roles: ROLE_USER }
        # The login form is embedded in the home page
        - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

但是我收到以下错误消息:

InvalidConfigurationException in ArrayNode.php line 237:
The child node "secret" at path "security.firewalls.main.remember_me" must be configured.

我究竟做错了什么?

更新资料

我已将密钥:“%secret%”更改为机密:“%secret%”.错误消失了,但是抛出了一个新错误:

You must configure at least one remember-me aware listener
(such as form-login) for each firewall that has remember-me enabled.

我通过在主防火墙下移动Remember_me:配置来解决此问题.

    main:
        anonymous: ~
        form_login:
            login_path: homepage
            check_path: login_check
            default_target_path: homepage
            failure_path: homepage
        logout:
            path:   /logout
            target: /
        remember_me:
            secret:      "%secret%"
            lifetime: 604800 # 1 week in seconds
            path:     /

解决方法:

在2.8版本中,关键参数被无证地重命名为secret …所以您应该这样做:

    remember_me:
        secret:      "%secret%"
        lifetime: 604800 # 1 week in seconds
        path:     /

查看https://github.com/symfony/symfony-docs/pull/5761

标签:symfony,login,remember-me,php
来源: https://codeday.me/bug/20191027/1947398.html