How to replace loadIdentifier() in Authenticator 3.3.0 to add a field in Authentication with AuthenticationService

Hello all!

This is my current implementation to check beside Username and Password that the User is enabled:

src/Model/Table/UsersTable.php:

    /**
     * Add the 'enabled' fields in authentication with AuthenticationService
     *
     * @param Query $query
     * @param array $options
     * @return Query
     */
    public function findEnabledUser(Query $query, array $options): Query
    {
        return $query->where(['Users.enabled' => true);
    }

src/Application.php:

public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface {
...
        // Load identifiers, ensure we check email and password fields
        $authenticationService->loadIdentifier('Authentication.Password', [
            'fields' => [
                'username' => 'username',
                'password' => 'password',
            ],
            'resolver' => [
                'className' => 'Authentication.Orm',
                'userModel' => 'Users',
                'finder' => 'enabledUser' // default: 'all'
            ],
        ]);
...

In Authentication 3.3.0 the loadIdentifier() usage is deprecated.

How do I directly pass Identifier to Authenticator?

Whats wrong with the documentation?

@dereuromark There is nothing wrong with the documentation, but how do I achieve the use of a customized Authentication function, which allows only “enabled" == true users?

Exactly as documented:

’identifier’ key with additional resolver info inside, e.g.

$passwordIdentifier = [
    'Authentication.Password' => [
        'fields' => $fields,
        'resolver' => [
            'className' => 'Authentication.Orm',
            'finder' => 'active',
        ],
    ],
];
$service->loadAuthenticator('Authentication.Form', [
    'urlChecker' => 'Authentication.CakeRouter',
    'identifier' => $passwordIdentifier,
    'fields' => ...,
    'loginUrl' => ...,
]);
1 Like

Thanks a lot! Now it works :slight_smile: