yiisoft / yiisoft/auth

Remove the 'ResponseFactoryInterface $responseFactory' parameter from the 'Authentication' constructor

Open
#129 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

severity:BC breaking status:under discussion
Dominant language
PHP
Stars
39
Forks
17
Avg merge
1h 9m
Merged PRs (30d)
1

Description

Proposed new feature or change

The 'ResponseFactoryInterface $responseFactory' parameter is proposed for removal from the 'Authentication' constructor in order to simplify the 'Authentication' configuration, while retaining the same logic.

Current:

final class Authentication implements MiddlewareInterface
{
    // ...
    public function __construct(
        private AuthenticatorInterface|AuthenticationMethodInterface $authenticationMethod,
        ResponseFactoryInterface $responseFactory,
        ?RequestHandlerInterface $authenticationFailureHandler = null,
    ) {
        $this->failureHandler = $authenticationFailureHandler ?? new AuthenticationFailureHandler(
            $responseFactory,
        );
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // ...
        if ($identity === null && !$this->isOptional($request)) {
            $response = $this->failureHandler->handle($request);
            // ...
        }
        // ...
    }
    // ...
}

Proposed:

final class Authentication implements MiddlewareInterface
{
    // ...
    public function __construct(
        private AuthenticatorInterface|AuthenticationMethodInterface $authenticationMethod,
        private RequestHandlerInterface $authenticationFailureHandler
    ) {}

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    { 
        // ...
        if ($identity === null && !$this->isOptional($request)) {
            $response = $this->authenticationFailureHandler->handle($request);
            // ...
        }
        // ...
    }
    // ...
}
//config/di-web.php
use App\Web\Auth\AuthenticationFailureHandler;
use Psr\Http\Server\RequestHandlerInterface;

return [
    RequestHandlerInterface::class => AuthenticationFailureHandler::class
];

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Authentication constructor and the config/di-web.php entry shown in the issue, then trace how AuthenticationFailureHandler and RequestHandlerInterface are wired and used. Done means Authentication no longer accepts ResponseFactoryInterface, its failure handler is supplied through the handler dependency, and the existing authentication-failure behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
authentication
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.