Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/Middleware/AuthenticationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@

try {
$result = $service->authenticate($request);
$authenticator = $service->getAuthenticationProvider();

if ($authenticator !== null && !$authenticator instanceof StatelessInterface) {
assert($result->getData() !== null);
$service->persistIdentity($request, new Response(), $result->getData());

Check failure on line 92 in src/Middleware/AuthenticationMiddleware.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

PossiblyNullArgument

src/Middleware/AuthenticationMiddleware.php:92:69: PossiblyNullArgument: Argument 3 of Authentication\AuthenticationServiceInterface::persistIdentity cannot be null, possibly null value provided (see https://psalm.dev/078)
Copy link
Copy Markdown
Member

@ADmad ADmad Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are ignoring the return value of persistIdentity(). When CookieAuthenticator is used the return value will contain the updated response instance with the header set for the cookie. So with your patch the cookie will never be set on the client.

Copy link
Copy Markdown
Member

@ADmad ADmad Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor you can return the response instance at this point as returning a response from the middleware will short circuit the response handling by the framework.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, how can we fix this up to adhere to that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing that can be done here. PSR-15's middleware implementation doesn't support passing an updated response instance down the queue, it can only pass down the request.

}

Check failure on line 94 in src/Middleware/AuthenticationMiddleware.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Blank line found at end of control structure
} catch (AuthenticationRequiredException $e) {
$body = new Stream('php://memory', 'rw');
$body->write($e->getBody());
Expand All @@ -104,16 +111,6 @@

try {
$response = $handler->handle($request);
$authenticator = $service->getAuthenticationProvider();

if ($authenticator !== null && !$authenticator instanceof StatelessInterface) {
/**
* @psalm-suppress PossiblyNullArgument
* @phpstan-ignore-next-line
*/
$return = $service->persistIdentity($request, $response, $result->getData());
$response = $return['response'];
}
} catch (UnauthenticatedException $e) {
$url = $service->getUnauthenticatedRedirectUrl($request);
if ($url) {
Expand Down
Loading