You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is a modified version of this file from following breadcrumbs of deprecation in symfony 5, most notably replacing Diactoros with PsrHttpFactory and passing it a single instance of Psr17Factory (from nyholm/psr-17) for all argument constructors ... I'm no expert though, so I'm really guessing things.
Thank you for all your work.
`
resourceServer = $resourceServer;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
KernelEvents::EXCEPTION => 'onKernelException'
];
}
/**
* @param ControllerEvent $event
* @throws OAuthServerException
*/
public function onKernelController(ControllerEvent $event): void
{
$controller = $event->getController();
/*
* $controller passed can be either a class or a Closure.
* This is not usual in Symfony but it may happen.
* If it is a class, it comes in array format
*/
if (!\is_array($controller)) {
return;
}
if ($controller[0] instanceof TokenAuthenticatedController) {
$request = $event->getRequest();
$psr17Factory = new Psr17Factory();
$psrRequest = (new PsrHttpFactory(
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17Factory
))->createRequest($request);
try {
$psrRequest = $this->resourceServer->validateAuthenticatedRequest($psrRequest);
} catch (OAuthServerException $exception) {
throw $exception;
} catch (\Exception $exception) {
throw new OAuthServerException($exception->getMessage(), 0, 'unknown_error', Response::HTTP_INTERNAL_SERVER_ERROR);
}
$this->enrichSymfonyRequestWithAuthData($request, $psrRequest);
}
}
/**
* @param Request $request
* @param ServerRequestInterface $psrRequest
*/
private function enrichSymfonyRequestWithAuthData(Request $request, ServerRequestInterface $psrRequest): void
{
$request = $request->request;
$requestArray = $request->all();
$requestArray['oauth_user_id'] = $psrRequest->getAttribute('oauth_user_id');
$requestArray['oauth_access_token_id'] = $psrRequest->getAttribute('oauth_access_token_id');
$requestArray['oauth_client_id'] = $psrRequest->getAttribute('oauth_client_id');
$request->replace($requestArray);
}
/**
* @param ExceptionEvent $event
*/
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
if (!($exception instanceof OAuthServerException)) {
return;
}
$response = new JsonResponse(['error' => $exception->getMessage()], $exception->getHttpStatusCode());
$event->setResponse($response);
}
}
`
The text was updated successfully, but these errors were encountered:
symfony4-oauth2-server-league/src/Application/EventSubscriber/TokenSubscriber.php
Line 64 in 01e1425
Below is a modified version of this file from following breadcrumbs of deprecation in symfony 5, most notably replacing Diactoros with PsrHttpFactory and passing it a single instance of Psr17Factory (from nyholm/psr-17) for all argument constructors ... I'm no expert though, so I'm really guessing things.
Thank you for all your work.
`
resourceServer = $resourceServer; } /** * @return array */ public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => 'onKernelController', KernelEvents::EXCEPTION => 'onKernelException' ]; } /** * @param ControllerEvent $event * @throws OAuthServerException */ public function onKernelController(ControllerEvent $event): void { $controller = $event->getController(); /* * $controller passed can be either a class or a Closure. * This is not usual in Symfony but it may happen. * If it is a class, it comes in array format */ if (!\is_array($controller)) { return; } if ($controller[0] instanceof TokenAuthenticatedController) { $request = $event->getRequest(); $psr17Factory = new Psr17Factory(); $psrRequest = (new PsrHttpFactory( $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory ))->createRequest($request); try { $psrRequest = $this->resourceServer->validateAuthenticatedRequest($psrRequest); } catch (OAuthServerException $exception) { throw $exception; } catch (\Exception $exception) { throw new OAuthServerException($exception->getMessage(), 0, 'unknown_error', Response::HTTP_INTERNAL_SERVER_ERROR); } $this->enrichSymfonyRequestWithAuthData($request, $psrRequest); } } /** * @param Request $request * @param ServerRequestInterface $psrRequest */ private function enrichSymfonyRequestWithAuthData(Request $request, ServerRequestInterface $psrRequest): void { $request = $request->request; $requestArray = $request->all(); $requestArray['oauth_user_id'] = $psrRequest->getAttribute('oauth_user_id'); $requestArray['oauth_access_token_id'] = $psrRequest->getAttribute('oauth_access_token_id'); $requestArray['oauth_client_id'] = $psrRequest->getAttribute('oauth_client_id'); $request->replace($requestArray); } /** * @param ExceptionEvent $event */ public function onKernelException(ExceptionEvent $event): void { $exception = $event->getThrowable(); if (!($exception instanceof OAuthServerException)) { return; } $response = new JsonResponse(['error' => $exception->getMessage()], $exception->getHttpStatusCode()); $event->setResponse($response); } } `The text was updated successfully, but these errors were encountered: