1818
1919use Authentication \Identifier \AbstractIdentifier ;
2020use Authentication \Identifier \IdentifierCollection ;
21+ use Authentication \Identifier \IdentifierInterface ;
2122use Authentication \UrlChecker \UrlCheckerTrait ;
2223use Cake \Routing \Router ;
2324use Psr \Http \Message \ServerRequestInterface ;
@@ -49,17 +50,14 @@ class FormAuthenticator extends AbstractAuthenticator
4950 ];
5051
5152 /**
52- * Authenticates the identity contained in a request. Will use the `config.userModel`, and `config.fields`
53- * to find POST data that is used to find a matching record in the `config.userModel`. Will return false if
54- * there is no post data, either username or password is missing, or if the scope conditions have not been met.
53+ * Gets the identifier, loading a default Password identifier if none configured.
5554 *
56- * @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
57- * @return \Authentication\Authenticator\ResultInterface
55+ * This is done lazily to allow loadIdentifier() to be called after loadAuthenticator().
56+ *
57+ * @return \Authentication\Identifier\IdentifierInterface
5858 */
59- public function authenticate ( ServerRequestInterface $ request ): ResultInterface
59+ public function getIdentifier ( ): IdentifierInterface
6060 {
61- // If no identifier is configured, set up a default Password identifier
62- // This is done lazily to allow loadIdentifier() to be called after loadAuthenticator()
6361 if ($ this ->_identifier instanceof IdentifierCollection && $ this ->_identifier ->isEmpty ()) {
6462 $ identifierConfig = [];
6563 if ($ this ->getConfig ('fields ' )) {
@@ -68,6 +66,19 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
6866 $ this ->_identifier ->load ('Authentication.Password ' , $ identifierConfig );
6967 }
7068
69+ return $ this ->_identifier ;
70+ }
71+
72+ /**
73+ * Authenticates the identity contained in a request. Will use the `config.userModel`, and `config.fields`
74+ * to find POST data that is used to find a matching record in the `config.userModel`. Will return false if
75+ * there is no post data, either username or password is missing, or if the scope conditions have not been met.
76+ *
77+ * @param \Psr\Http\Message\ServerRequestInterface $request The request that contains login information.
78+ * @return \Authentication\Authenticator\ResultInterface
79+ */
80+ public function authenticate (ServerRequestInterface $ request ): ResultInterface
81+ {
7182 if (!$ this ->_checkUrl ($ request )) {
7283 return $ this ->_buildLoginUrlErrorResult ($ request );
7384 }
@@ -79,10 +90,11 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
7990 ]);
8091 }
8192
82- $ user = $ this ->_identifier ->identify ($ data );
93+ $ identifier = $ this ->getIdentifier ();
94+ $ user = $ identifier ->identify ($ data );
8395
8496 if (!$ user ) {
85- return new Result (null , Result::FAILURE_IDENTITY_NOT_FOUND , $ this -> _identifier ->getErrors ());
97+ return new Result (null , Result::FAILURE_IDENTITY_NOT_FOUND , $ identifier ->getErrors ());
8698 }
8799
88100 return new Result ($ user , Result::SUCCESS );
0 commit comments