Skip to content

Login programmatically not working without  #48595

@LeamasRein

Description

@LeamasRein

Symfony version(s) affected

6.2

Description

The new ability to programmatically login does not work if at least one authenticator is not declared in config.

How to reproduce

  1. Create auth controller with $security (Symfony\Bundle\SecurityBundle\Security) and u user repo.
  2. Fetch any profile from repo and use $security->login($user).
  3. Catch exception "Call to a member function getProvidedServices() on null" in vendor/symfony/security-bundle/Security.php:122.

Possible Solution

I "solved" the problem by adding an empty authenticator to the project.

security:
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: username
        # used to reload user from session & other features (e.g. switch_user)
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            lazy: false
            provider: app_user_provider
            custom_authenticators:
                - App\Security\EmptyAuthenticator

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions