Skip to content

[Security][UserBadge] EntityUserProvider missing attibutes on loadUserByIdentifier #61809

@ytilotti

Description

@ytilotti

Symfony version(s) affected

7.2

Description

In the userBadge class and the function getUser there is this code:

if (null === $this->getAttributes()) {
    $user = ($this->userLoader)($this->userIdentifier);
} else {
    $user = ($this->userLoader)($this->userIdentifier, $this->getAttributes());
}

And in the class EntityUserProvider there is the function:

public function loadUserByIdentifier(string $identifier): UserInterface
{
    //...
}

The second attribute is missing of the function is missing is there are attributes in the UserBadge.
Same in the Interface, ...

The problem that is you set attributes it's not possible to get these in loadUserByIdentifier in the repository via https://symfony.com/doc/current/security/user_providers.html#creating-a-custom-user-provider

How to reproduce

To reproduce it, direction the Authenticator:

public function authenticate(Request $request): Passport
    {
        $credentials = $this->getCredentials($request);

        $passport = new Passport(
            new UserBadge($credentials['username'], [$this->userProvider, 'loadUserByIdentifier'], ['interface' => $credentials['interface']]),
            new PasswordCredentials($credentials['password']),
            [
                new RememberMeBadge(),
            ]
        );

        return $passport;
    }

The interface parameter is impossible to get in the UsersRepository:

phppublic function loadUserByIdentifier(string $identifier, array $attributes = []): ?UserInterface
{
    dd($attributes);
}

$attributes is empty.

Possible Solution

No response

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