PHP code example of stgbundle / cas-bundle

1. Go to this page and download the library: Download stgbundle/cas-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stgbundle / cas-bundle example snippets


return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class   => ['all' => true],
    STG\DEIM\Security\Bundle\CasBundle\CasBundle::class  => ['all' => true],
    // ... otros bundles
];

// src/Controller/DefaultController.php
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class DefaultController
{
    #[Route('/failure', name: 'failure')]    
    public function failure(Request $request): Response
    {
        return new Response(
            'Error al autenticar - Usuario: ' . $request->get('user')
        );
    }

    #[Route('/secure/logout', name: 'logout')]
    public function logout()
    {
    }

    #[Route('/cas/check', name: 'cas_check')]
    public function casCheck(): Response
    {
        // El CasAuthenticator intercepta esta ruta cuando CAS redirige con ?ticket=
        // Si se llega aquí sin ticket, redirigir al inicio.
        return new RedirectResponse('/');
    }