1717
1818use ArrayAccess ;
1919use ArrayObject ;
20+ use Authentication \Identifier \IdentifierFactory ;
21+ use Authentication \Identifier \IdentifierInterface ;
2022use Authentication \Identifier \PasswordIdentifier ;
2123use Cake \Http \Exception \UnauthorizedException ;
2224use Psr \Http \Message \ResponseInterface ;
@@ -47,6 +49,25 @@ class SessionAuthenticator extends AbstractAuthenticator implements PersistenceI
4749 'identityAttribute ' => 'identity ' ,
4850 ];
4951
52+ /**
53+ * Constructor
54+ *
55+ * @param \Authentication\Identifier\IdentifierInterface|null $identifier Identifier instance.
56+ * @param array<string, mixed> $config Configuration settings.
57+ */
58+ public function __construct (?IdentifierInterface $ identifier , array $ config = [])
59+ {
60+ if ($ identifier === null ) {
61+ $ identifierConfig = [];
62+ if (isset ($ config ['fields ' ])) {
63+ $ identifierConfig ['fields ' ] = $ config ['fields ' ];
64+ }
65+ $ identifier = IdentifierFactory::create ('Authentication.Password ' , $ identifierConfig );
66+ }
67+
68+ parent ::__construct ($ identifier , $ config );
69+ }
70+
5071 /**
5172 * Authenticate a user using session data.
5273 *
@@ -69,7 +90,6 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
6990 foreach ($ this ->getConfig ('fields ' ) as $ key => $ field ) {
7091 $ credentials [$ key ] = $ user [$ field ];
7192 }
72- assert ($ this ->_identifier !== null );
7393 $ user = $ this ->_identifier ->identify ($ credentials );
7494
7595 if (!$ user ) {
0 commit comments