-
-
Notifications
You must be signed in to change notification settings - Fork 14
refactor middleware authentication failure handler #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b645f30
35ca455
2bf510a
cfbad1d
c83a7c5
0811e9b
a2f4889
594bcfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |||
|
|
||||
| ## 3.2.2 under development | ||||
|
|
||||
| - Enh #101: Refactor `Authentication` middleware authentication failure handling (@olegbaturin) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create UPGRADE.md. |
||||
| - Chg #101: Change PHP constraint in composer.json to 8.1 - 8.4 (@olegbaturin) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| - Chg #104: Bump minimal PHP version to 8.1 (@vjik) | ||||
| - Enh #104: Explicitly mark readonly properties (@vjik) | ||||
|
|
||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Yiisoft\Auth\AuthenticationFailureHandler; | ||
| use Yiisoft\Auth\AuthenticationFailureHandlerInterface; | ||
|
|
||
| /** | ||
| * @var array $params | ||
| */ | ||
|
|
||
| return [ | ||
| AuthenticationFailureHandlerInterface::class => AuthenticationFailureHandler::class, | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,17 @@ | |
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Auth\Handler; | ||
| namespace Yiisoft\Auth; | ||
|
|
||
| use Psr\Http\Message\ResponseFactoryInterface; | ||
| use Psr\Http\Message\ResponseInterface; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use Psr\Http\Server\RequestHandlerInterface; | ||
| use Yiisoft\Http\Status; | ||
|
|
||
| /** | ||
| * Default authentication failure handler. Responds with "401 Unauthorized" HTTP status code. | ||
| */ | ||
| final class AuthenticationFailureHandler implements RequestHandlerInterface | ||
| final class AuthenticationFailureHandler implements AuthenticationFailureHandlerInterface | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the benefit in having a dedicated interface? Ability to configure it with a single line only? @vjik is there a better way?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| public function __construct( | ||
| private readonly ResponseFactoryInterface $responseFactory, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Auth; | ||
|
|
||
| use Psr\Http\Message\ResponseInterface; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
|
|
||
| /** | ||
| * `AuthenticationFailureHandlerInterface` produces a response when there is a failure authenticating an identity. | ||
| */ | ||
| interface AuthenticationFailureHandlerInterface | ||
| { | ||
| public function handle(ServerRequestInterface $request): ResponseInterface; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Request\Body\Tests; | ||
|
|
||
| use Nyholm\Psr7\Factory\Psr17Factory; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Http\Message\ResponseFactoryInterface; | ||
| use Yiisoft\Di\Container; | ||
| use Yiisoft\Di\ContainerConfig; | ||
| use Yiisoft\Auth\AuthenticationFailureHandler; | ||
| use Yiisoft\Auth\AuthenticationFailureHandlerInterface; | ||
|
|
||
| use function dirname; | ||
|
|
||
| final class ConfigTest extends TestCase | ||
| { | ||
| public function testAuthenticationFailureHandler(): void | ||
| { | ||
| $container = $this->createContainer(); | ||
|
|
||
| $failureHandler = $container->get(AuthenticationFailureHandlerInterface::class); | ||
| $this->assertInstanceOf(AuthenticationFailureHandler::class, $failureHandler); | ||
| } | ||
|
|
||
| private function createContainer(): Container | ||
| { | ||
| return new Container( | ||
| ContainerConfig::create()->withDefinitions([ | ||
| ResponseFactoryInterface::class => Psr17Factory::class, | ||
| ...$this->getContainerDefinitions(), | ||
| ]) | ||
| ); | ||
| } | ||
|
|
||
| private function getContainerDefinitions(): array | ||
| { | ||
| return require dirname(__DIR__) . '/config/di-web.php'; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "Chg" and replace "refactor" to concrete changes.