Add doc
This commit is contained in:
72
examples/TrackMania.php
Normal file
72
examples/TrackMania.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace App\Controller\OAuth2;
|
||||
|
||||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
class TrackMania extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Link to this controller to start the "connect" process
|
||||
*/
|
||||
#[Route(
|
||||
'/connect/trackmania',
|
||||
name: 'connect_trackmania_start'
|
||||
)]
|
||||
public function connectAction(ClientRegistry $clientRegistry)
|
||||
{
|
||||
// will redirect to Ubisoft Connect OAuth2
|
||||
return $clientRegistry
|
||||
->getClient('TrackMania') // key used in config/packages/knpu_oauth2_client.yaml
|
||||
->redirect([],[]);
|
||||
}
|
||||
|
||||
/**
|
||||
* After going to Ubisoft Connect OAuth2, you're redirected back here
|
||||
* because this is the "redirect_route" you configured
|
||||
* in config/packages/knpu_oauth2_client.yaml
|
||||
*/
|
||||
#[Route(
|
||||
'/connect/trackmania/check',
|
||||
name: 'connect_trackmania_check'
|
||||
)]
|
||||
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry)
|
||||
{
|
||||
// ** if you want to *authenticate* the user, then
|
||||
// leave this method blank and create a Guard authenticator
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/login',
|
||||
name: 'app_login',
|
||||
methods: ['GET', 'HEAD']
|
||||
)]
|
||||
public function login(Request $request, RequestStack $requestStack): RedirectResponse
|
||||
{
|
||||
$referer = $request->headers->get('referer');
|
||||
if ($referer !== null) {
|
||||
$session = $requestStack->getSession();
|
||||
$session->set("PostLoginRedirect", $referer);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('connect_trackmania_start');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/logout", name="app_logout", methods={"GET"})
|
||||
*/
|
||||
#[Route(
|
||||
'/logout',
|
||||
name: 'app_logout',
|
||||
methods: ['GET', 'HEAD']
|
||||
)]
|
||||
public function logout(): void
|
||||
{
|
||||
// controller can be blank: it will never be called!
|
||||
throw new \Exception('Don\'t forget to activate logout in security.yaml');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user