Skip to content

Commit b4bd380

Browse files
committed
Fix design flaw in auth process.
1 parent 3ae3563 commit b4bd380

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/Middleware/AuthenticationMiddleware.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8585

8686
try {
8787
$result = $service->authenticate($request);
88+
$authenticator = $service->getAuthenticationProvider();
89+
90+
if ($authenticator !== null && !$authenticator instanceof StatelessInterface) {
91+
assert($result->getData() !== null);
92+
$service->persistIdentity($request, new Response(), $result->getData());
93+
}
94+
8895
} catch (AuthenticationRequiredException $e) {
8996
$body = new Stream('php://memory', 'rw');
9097
$body->write($e->getBody());
@@ -104,16 +111,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
104111

105112
try {
106113
$response = $handler->handle($request);
107-
$authenticator = $service->getAuthenticationProvider();
108-
109-
if ($authenticator !== null && !$authenticator instanceof StatelessInterface) {
110-
/**
111-
* @psalm-suppress PossiblyNullArgument
112-
* @phpstan-ignore-next-line
113-
*/
114-
$return = $service->persistIdentity($request, $response, $result->getData());
115-
$response = $return['response'];
116-
}
117114
} catch (UnauthenticatedException $e) {
118115
$url = $service->getUnauthenticatedRedirectUrl($request);
119116
if ($url) {

0 commit comments

Comments
 (0)