Skip to content

Commit

Permalink
changed RestAuthenticator to be triggered by route instead of headers
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Jun 5, 2024
1 parent 15fe874 commit b0508ca
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/lib/Security/Authenticator/RestAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

final class RestAuthenticator extends AbstractAuthenticator implements InteractiveAuthenticatorInterface
{
private const string ACCEPT_HEADER = 'Accept';
private const string CONTENT_TYPE_HEADER = 'Content-Type';
private const string SESSION_HEADER_VALUE = 'application/vnd.ibexa.api.Session';
private const string SESSION_INPUT_HEADER_VALUE = 'application/vnd.ibexa.api.SessionInput';
private const string LOGIN_ROUTE = 'ibexa.rest.create_session';

public function __construct(
private readonly Dispatcher $inputDispatcher,
Expand All @@ -36,17 +33,7 @@ public function __construct(

public function supports(Request $request): ?bool
{
return
$request->headers->has(self::ACCEPT_HEADER) &&
$request->headers->has(self::CONTENT_TYPE_HEADER) &&
str_contains(
$request->headers->get(self::ACCEPT_HEADER) ?? '',
self::SESSION_HEADER_VALUE
) &&
str_contains(
$request->headers->get(self::CONTENT_TYPE_HEADER) ?? '',
self::SESSION_INPUT_HEADER_VALUE
);
return $request->attributes->get('_route') === self::LOGIN_ROUTE;
}

public function authenticate(Request $request): Passport
Expand Down

0 comments on commit b0508ca

Please sign in to comment.