CsrfTokenController.php in Drupal 10
File
core/modules/system/src/Controller/CsrfTokenController.php
View source
<?php
namespace Drupal\system\Controller;
use Drupal\Core\Access\CsrfRequestHeaderAccessCheck;
use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
class CsrfTokenController implements ContainerInjectionInterface {
protected $tokenGenerator;
public function __construct(CsrfTokenGenerator $token_generator) {
$this->tokenGenerator = $token_generator;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('csrf_token'));
}
public function csrfToken() {
return new Response($this->tokenGenerator
->get(CsrfRequestHeaderAccessCheck::TOKEN_KEY), 200, [
'Content-Type' => 'text/plain',
]);
}
}