D
D
d999992021-03-01 22:59:16
symfony
d99999, 2021-03-01 22:59:16

Why does Google authentication API throw an Invalid state error?

I use knpu university bundle

/**
     * @Route("/connect-google", name="connect_google_start")
     * @param ClientRegistry $clientRegistry
     * @return Response
     */
    public function connectFacebookAction(ClientRegistry $clientRegistry): Response
    {
        return $clientRegistry
            ->getClient('google_main')
            ->redirect([
                'profile', 'email'
            ], []);
    }

    /**
     * @Route("/google-check", name="google_check")
     *
     * @param Request $request
     * @param ClientRegistry $clientRegistry
     * @return RedirectResponse
     */
    public function connectGoogleCheckAction(Request $request, ClientRegistry $clientRegistry)
    {
        $client = $clientRegistry->getClient('google_main');
        try {
            //be sure you use dev.pro VPN
            $user = $client->fetchUser();
            //В этом участке кода ошибка


            exit;

            $this->googleService->storeOrAuth($user, $request);
        } catch (IdentityProviderException $e) {
            $this->logger->error('Google authorization: ' . $e->getMessage());
        }

        return $this->redirectToRoute('home');
    }

603d4778f18bb345620998.png

Settings
google_main:
            type: google
            client_id: '%env(OAUTH_GOOGLE_ID)%'
            client_secret: '%env(OAUTH_GOOGLE_SECRET)%'
            redirect_route: google_check
            redirect_params: {}
            access_type: 'offline'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d99999, 2021-03-03
@d99999

Need to set - do not check state

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question