4
4
5
5
namespace Scheb \TwoFactorBundle \DependencyInjection ;
6
6
7
- use OTPHP \TOTP ;
8
- use ReflectionMethod ;
9
- use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
10
7
use Symfony \Component \Config \FileLocator ;
11
8
use Symfony \Component \DependencyInjection \Argument \IteratorArgument ;
12
9
use Symfony \Component \DependencyInjection \ContainerBuilder ;
13
10
use Symfony \Component \DependencyInjection \Loader ;
14
11
use Symfony \Component \DependencyInjection \Reference ;
15
12
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
16
13
use function assert ;
17
- use function class_exists ;
18
- use function count ;
19
14
use function is_bool ;
20
15
use function is_string ;
21
16
use function trim ;
@@ -193,19 +188,13 @@ private function configureEmailAuthenticationProvider(ContainerBuilder $containe
193
188
*/
194
189
private function configureGoogleAuthenticationProvider (ContainerBuilder $ container , array $ config ): void
195
190
{
196
- // Migration path for the "leeway" option, to be fully migrated in bundle version 7
197
- if (null !== $ config ['google ' ]['leeway ' ] && !$ this ->isSpomkyOtphpVersion11Used ()) {
198
- throw new InvalidConfigurationException ('The "leeway" option can only be set when spomky-labs/otphp v11 is used. ' );
199
- }
200
-
201
191
$ loader = new Loader \PhpFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
202
192
$ loader ->load ('two_factor_provider_google.php ' );
203
193
204
194
$ container ->setParameter ('scheb_two_factor.google.server_name ' , $ config ['google ' ]['server_name ' ]);
205
195
$ container ->setParameter ('scheb_two_factor.google.issuer ' , $ config ['google ' ]['issuer ' ]);
206
196
$ container ->setParameter ('scheb_two_factor.google.template ' , $ config ['google ' ]['template ' ]);
207
197
$ container ->setParameter ('scheb_two_factor.google.digits ' , $ config ['google ' ]['digits ' ]);
208
- $ container ->setParameter ('scheb_two_factor.google.window ' , $ config ['google ' ]['window ' ]);
209
198
$ container ->setParameter ('scheb_two_factor.google.leeway ' , $ config ['google ' ]['leeway ' ]);
210
199
211
200
if (null === $ config ['google ' ]['form_renderer ' ]) {
@@ -220,17 +209,11 @@ private function configureGoogleAuthenticationProvider(ContainerBuilder $contain
220
209
*/
221
210
private function configureTotpAuthenticationProvider (ContainerBuilder $ container , array $ config ): void
222
211
{
223
- // Migration path for the "leeway" option, to be fully migrated in bundle version 7
224
- if (null !== $ config ['totp ' ]['leeway ' ] && !$ this ->isSpomkyOtphpVersion11Used ()) {
225
- throw new InvalidConfigurationException ('The "leeway" option can only be set when spomky-labs/otphp v11 is used. ' );
226
- }
227
-
228
212
$ loader = new Loader \PhpFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
229
213
$ loader ->load ('two_factor_provider_totp.php ' );
230
214
231
215
$ container ->setParameter ('scheb_two_factor.totp.issuer ' , $ config ['totp ' ]['issuer ' ]);
232
216
$ container ->setParameter ('scheb_two_factor.totp.server_name ' , $ config ['totp ' ]['server_name ' ]);
233
- $ container ->setParameter ('scheb_two_factor.totp.window ' , $ config ['totp ' ]['window ' ]);
234
217
$ container ->setParameter ('scheb_two_factor.totp.parameters ' , $ config ['totp ' ]['parameters ' ]);
235
218
$ container ->setParameter ('scheb_two_factor.totp.template ' , $ config ['totp ' ]['template ' ]);
236
219
$ container ->setParameter ('scheb_two_factor.totp.leeway ' , $ config ['totp ' ]['leeway ' ]);
@@ -242,18 +225,6 @@ private function configureTotpAuthenticationProvider(ContainerBuilder $container
242
225
$ container ->setAlias ('scheb_two_factor.security.totp.form_renderer ' , $ config ['totp ' ]['form_renderer ' ]);
243
226
}
244
227
245
- private function isSpomkyOtphpVersion11Used (): bool
246
- {
247
- if (!class_exists (TOTP ::class)) {
248
- return false ;
249
- }
250
-
251
- $ parameters = (new ReflectionMethod (TOTP ::class, 'verify ' ))->getParameters ();
252
-
253
- // Third parameter must be named "leeway"
254
- return count ($ parameters ) >= 3 && 'leeway ' === $ parameters [2 ]->getName ();
255
- }
256
-
257
228
private function resolveFeatureFlag (ContainerBuilder $ container , bool |string $ value ): bool
258
229
{
259
230
$ retValue = $ container ->resolveEnvPlaceholders ($ value , true );
0 commit comments