<?php
namespace App\Controller\Oauth;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class GoogleController extends AbstractController
{
/**
* Link to this controller to start the "connect" process
* @param ClientRegistry $clientRegistry
*
* @Route("/connect/google", name="connect_google_start")
*
* @return RedirectResponse
*/
public function connectAction(ClientRegistry $clientRegistry)
{
return $clientRegistry
->getClient('google')
->redirect(
[
'profile',
'email' // the scopes you want to access,
],
[]
);
}
/**
* After going to Google, you're redirected back here
* because this is the "redirect_route" you configured
* in config/packages/knpu_oauth2_client.yaml
*
* @param Request $request
* @param ClientRegistry $clientRegistry
*
* @Route("/connect/google/check", name="connect_google_check")
* @return RedirectResponse
*/
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry)
{
return $this->redirectToRoute('dashboard');
}
}