src/Controller/TinyKnightGames/Authentication/AuthenticationController.php line 14
<?php
namespace App\Controller\TinyKnightGames\Authentication;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class AuthenticationController extends AbstractController
{
#[Route('/connect/google', name: 'connect_google_start')]
public function connectGoogleStart(ClientRegistry $clientRegistry)
{
return $clientRegistry
->getClient('google_main') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([
'profile', 'email' // the scopes you want to access
]);
}
#[Route('/connect/google/check', name: 'connect_google_check')]
public function connectGoogleCheck(ClientRegistry $clientRegistry)
{
$client = $clientRegistry->getClient('google_main');
try {
/** @var \League\OAuth2\Client\Provider\GoogleUser */
$user = $client->fetchUser();
} catch (IdentityProviderException $e) {
var_dump($e->getMessage());
die();
}
return $clientRegistry
->getClient('google_main') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([
'profile', 'email' // the scopes you want to access
]);
}
}