I
I
Igor2019-11-05 13:24:41
symfony
Igor, 2019-11-05 13:24:41

Symfony guard entry_point?

Colleagues, welcome!
Problem with authorization

firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        # Вызывается каждый раз, когда я запрашиваю /security.getAccessToken
        get_access_token:
            pattern: ^/security.getAccessToken
            guard:
                entry_point: App\Security\CreateAccessToken

        # Вызывается каждый раз, когда я запрашиваю /security.checkAccessToken
        check_access_token:
            pattern: ^/security.checkAccessToken
            guard:
                entry_point: App\Security\CheckAccessToken

        # Вызывается каждый раз, когда я запрашиваю любой другой роут
        main:
            guard:
                entry_point: App\Security\TokenAuthenticator

Symfony obliges me to return a Response object from the start method
class TokenAuthenticator implements AuthenticationEntryPointInterface
{
...
/**
     * @param Request $request
     * @param AuthenticationException|null $authException
     * @return Response
     * @throws EAuthorisationError
     * @throws ExceptionInvalidRequest
     */
    public function start(Request $request, AuthenticationException $authException = null)
    {
        if (!$this->supports($request)) {
            throw new ExceptionInvalidRequest("Требуется параметр [token]!", $request);
        }

        $credentials = $this->getCredentials($request);

        if ($this->verification($credentials["token"])) {
            return new Response(params);
        }

        throw new EAuthorisationError("Token is not valid!");
    }

But I need to continue the query, where am I going wrong?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2019-11-05
@IgorPI

https://symfony.com/doc/current/security/multiple_...

firewalls:
    main:
        guard:
            authenticators: 
                - App\Security\TokenAuthenticator

entry_point- used to start the authentication process. In your case, it is not needed, because. do you have api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question