What is the purpose of the AuthenticatorInterface::supports() method? What is the purpose of the AuthenticatorInterface::supports() method? symfony symfony

What is the purpose of the AuthenticatorInterface::supports() method?


I agree this feature isn't that well documented (yet). The only thing I can find is this:

How to Create a Custom Authentication System with Guard

supports(Request $request)

This will be called on every request andyour job is to decide if the authenticator should be used for thisrequest (return true) or if it should be skipped (return false).

For example: you can use the Request to check if it is a XMLHttpRequest (AJAX), so you can have dedicated AjaxAuthenticator.

A similar feature (VoterInterface::support()) is documented at How to Use Voters to Check User Permissions.


This interface comes in replacement of GuardAuthenticationInterface that is deprecated in Symfony 3.4, and removed from Symfony 3.4.

This difference is that the former GuardAuthenticationInterface only defined a getCredentials method that returns NULL or any form of credentials. In some cases there are many ways to get the credentials for an authenticator, the getCredentials method was processed any way, until something is returned, or end without returning anything (that is almost equivalent to a null return).

When you use multiple authenticators, you don't want to wait each one to return nothing to pass to the following one. So that this supports method appeared in order to return if, yes or no, the authenticator getCredentials method must be called. Note that in the new AuthenticationInterface, getCredentials method is always supposed to return something.

Here is an article from Symfony's blog that describes the move