Skip to content

Commit 3e3651e

Browse files
committed
bug #469 Fixed make:auth when using a custom repository method as UserProvider (romaricdrigon)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fixed make:auth when using a custom repository method as UserProvider Hello, It is possible in vanilla Symfony to change how the User is retrieved by the `entity` user provider, so you use your own repository - [https://symfony.com/doc/current/security/user_provider.html#using-a-custom-query-to-load-the-user](https://symfony.com/doc/current/security/user_provider.html#using-a-custom-query-to-load-the-user). Then you remove `providers.xxxx.entity.property` key. Unfortunately, it causes `make:auth` command to crash: ![image](https://user-images.githubusercontent.com/919405/64244498-6fde3680-cf09-11e9-8edb-79db50b3936e.png) This PR patches `InteractiveSecurityHelper`, so it checks `property` key exists before reading from it. No BC break. I added a test for that very specific use case. Commits ------- 7014d93 Fixed make:auth when using a custom repository method as UserProvider
2 parents e86b30c + 7014d93 commit 3e3651e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/Security/InteractiveSecurityHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private function guessUserClassDefault(): string
114114

115115
public function guessUserNameField(SymfonyStyle $io, string $userClass, array $providers): string
116116
{
117-
if (1 === \count($providers) && isset(current($providers)['entity'])) {
117+
if (1 === \count($providers) && isset(current($providers)['entity']) && isset(current($providers)['entity']['property'])) {
118118
$entityProvider = current($providers);
119119

120120
return $entityProvider['entity']['property'];

tests/Maker/FunctionalTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ function (string $output, string $directory) {
438438
'AppCustomAuthenticator',
439439
// controller name
440440
'SecurityController',
441+
// field name
442+
'userEmail',
441443
"no"
442444
]
443445
)

tests/Security/InteractiveSecurityHelperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ public function getUsernameFieldsTest()
187187
true
188188
];
189189

190+
yield 'guess_with_providers_and_custom_repository_method' => [
191+
'providers' => ['app_provider' => ['entity' => null]],
192+
'expectedUsernameField' => 'email',
193+
true,
194+
FixtureClass::class
195+
];
196+
190197
yield 'guess_fixture_class' => [
191198
'providers' => [],
192199
'expectedUsernameField' => 'email',

0 commit comments

Comments
 (0)