Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 24 additions & 1 deletion src/Domain/Process/OAuth2/GrantAccessByOAuth2TokenProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
use Exception;
use Lcobucci\JWT\Token\RegisteredClaims;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
use Throwable;

final class GrantAccessByOAuth2TokenProcess
Expand Down Expand Up @@ -125,6 +127,27 @@ public function createRedirectResponseForRequest(Request $request, UserOAuthLogi
private function logException(Request $request, Throwable $throwable): void
{
$context = $this->contextFactory->buildFromRequest($request);

$content = $throwable->getTraceAsString();
$prevException = $throwable->getPrevious();
if ($prevException) {
$content .= "\nPrevious exception:\n" . $prevException->getTraceAsString();
}
if ($prevException instanceof HttpExceptionInterface) {
$response = $prevException->getResponse();
try {
$context
->setHttpStatus($response->getStatusCode())
->setResponse($response->getContent())
;
} catch (ExceptionInterface $responseException) {
$context
->setResponse(sprintf('Failed to retrieve a response content! (error: %s)', $responseException->getMessage()))
;
}
}

$context->setContent($content);
$arrayContext = $this->serializer->toArray($context);
if (false === is_array($arrayContext)) {
$arrayContext = [];
Expand Down
7 changes: 6 additions & 1 deletion src/Security/Authentication/ApiTokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio

private function getCredentials(Request $request): array
{
return u((string) $request->headers->get('Authorization'))
$credentials = u((string) $request->headers->get('Authorization'))
->replaceMatches('~Bearer[\s+]~', '')
->trim()
->split(':', 2);
if (2 === count($credentials)) {
return $credentials;
}

return [null, null];
}

private function checkCredentials(string $token, ApiTokenUserInterface $user): bool
Expand Down