2

Пытаюсь подключить аутентификацию через facebook на тестовом сайте на Symfony 4.3 После клика на кнопку войти через facebook меня просто кидает обратно на страницу логина безо всяких ошибок и предупреждений. Полазив по отдадчику обнаружил такую интересную вещь: запрос даже не доходит до FacebookAuthenticator!!

введите сюда описание изображения

Как видите, он проверяет App\Security\LoginFormAuthenticator - не подходит, затем проверяет App\Security\OAuth\FacebookAuthenticator - тоже не подходит, хотя должен подходить!

Вот фрагмент security.yaml

    guard:
        authenticators:
            - App\Security\LoginFormAuthenticator
            - App\Security\OAuth\FacebookAuthenticator
        entry_point: App\Security\LoginFormAuthenticator

Вот метод supports класса App\Security\OAuth\FacebookAuthenticator

public function supports(Request $request): bool
{
    $this->logger->info("Check this 1986: ".$request->attributes->get('_route'));
    return $request->attributes->get('_route') === 'oauth.facebook_check';
}

Кстати в логгер мне пишет это:

[2019-11-26 13:05:18] app.INFO: Check this 1986: app_login [] []

При попытке подменить роут oauth.facebook_check на app_login symfony пишет мне ошибку "Invalid state parameter passed in callback URL."

Вот часть из моего шаблона:

                    <div class="row">
                        <div class="col-12">
                            <a class="btn btn-block btn-facebook" href="{{ path('oauth.facebook') }}">
                                <span>Log in by facebook</span>
                            </a>
                        </div>
                    </div>

Вот контроллер:

<?php
declare(strict_types=1);

namespace App\Controller\Auth\OAuth;

use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class FacebookController extends AbstractController
{

    /**
     * @Route(path="/oauth/facebook", name="oauth.facebook")
     * @param ClientRegistry $clientRegistry
     * @return Response
     */
    public function connect(ClientRegistry $clientRegistry): Response
    {
        return $clientRegistry
            ->getClient('facebook_main')
            ->redirect(['public_profile']);
    }

    /**
     * @Route(path="oauth/facebook/check", name="oauth.facebook_check")
     * @return Response
     */
    public function check(): Response
    {
        return $this->redirectToRoute("home");
    }
}

Почему метод supports класса App\Security\OAuth\FacebookAuthenticator не срабатывает??? Ведь текущий роут должен совпадать с роутом, когда я кликаю по кнопке "Log in by facebook".

3
  • В supports вам приходит роут app_login а он и не совпадает с oauth.facebook_check
    – Alpha
    26 ноя 2019 в 13:57
  • Alpha, я вижу. Вопрос: почему? Ведь я перехожу по href="{{ path('oauth.facebook') }}" который в браузере превращается в url /oauth/facebook
    – F. Tomas
    26 ноя 2019 в 16:28
  • Добавьте полностью security.yaml 20 фев 2020 в 14:45

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.