Symfony 4 - 自定义身份验证 FosUserBundle

Symfony 4 - custom authentication FosUserBundle

朋友,

我需要 Symfony4 方面的帮助。我为 FosUserBundle 构建自定义身份验证系统。 (我需要转换它)。

我的行为基于 Symfony 文档

https://symfony.com/doc/4.1/security/custom_authentication_provider.html

并且根据文档,我创建了所有真实文件。我不会把它们扔进去,因为这与文档中的相同。

我得到这个错误:

Not configuring explicitly the provider for the "wsse" listener on "main" firewall is ambiguous as there is more than one registered provider.

这是我的security.yaml

安全: # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers 编码器: FOS\UserBundle\Model\UserInterface: 加密

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]

providers:
    in_memory: { memory: ~ }
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        pattern: ^/
        stateless: true
        wsse:      true
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
            default_target_path: /

        logout:
            path: /logout
            target: /login
        anonymous: true

        # activate different ways to authenticate

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

        # form_login: true
        # https://symfony.com/doc/current/security/form_login_setup.html

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, role: ROLE_USER }
    - { path: ^/admin/, role: ROLE_ADMIN }

编辑

服务提供商

App\Security\Authentication\Provider\WsseProvider:
        arguments:
            $userProviderInterface: '@fos_user.user_provider.username'
            $cachePool: '@cache.app'
        public: false

我正在寻求帮助,因为我被卡住了

谢谢

在你的 security.yml 添加:

providers:
    wsse:
        id: App\Security\wsseProvider #class of UserProviderInterface

firewalls:
    main:
        ...
        form_login:
            provider: wsse

于 services.yaml

services:
  App\Security\wsseProvider:
    autowire: true
    public: false