Skip to content

[Improvement] Set default Identifiers based on the default configuration #735

@umer936

Description

@umer936

Extended from #733 , expanded into it's own issue as the previous is addressed.

Identifiers are now to be set per Authenticator.
But some Authenticators ask for an Identifier when they may not need one. For example, Form shouldn't need one if it's [username, password] as those are the default fields https://github.com/cakephp/authentication/blob/3.x/src/Authenticator/FormAuthenticator.php#L44 , so IMO the default Identifier should be Authentication.Password.

This feels like it should be enough

    public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
    {
        $service = new AuthenticationService([
            'unauthenticatedRedirect' => [
                'prefix' => false,
                'plugin' => null,
                'controller' => 'Users',
                'action' => 'login',
            ],
            'queryParam' => 'redirect',
        ]);

        // Load the authenticators. Session should be first.
        $service->loadAuthenticator('Authentication.Session');
        $service->loadAuthenticator('Authentication.Form');

        return $service;
    }

Rather than needing to do this:

    public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
    {
        $service = new AuthenticationService([
            'unauthenticatedRedirect' => [
                'prefix' => false,
                'plugin' => null,
                'controller' => 'Users',
                'action' => 'login',
            ],
            'queryParam' => 'redirect',
        ]);

        // Load the authenticators. Session should be first.
        $service->loadAuthenticator('Authentication.Session');
        $service->loadAuthenticator('Authentication.Form', [
            'identifier' => 'Authentication.Password',
        ]);

        return $service;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions