class CsrfTokenController

Same name in other branches
  1. 9 core/modules/system/src/Controller/CsrfTokenController.php \Drupal\system\Controller\CsrfTokenController
  2. 8.9.x core/modules/system/src/Controller/CsrfTokenController.php \Drupal\system\Controller\CsrfTokenController
  3. 11.x core/modules/system/src/Controller/CsrfTokenController.php \Drupal\system\Controller\CsrfTokenController

Returns responses for CSRF token routes.

Hierarchy

Expanded class hierarchy of CsrfTokenController

File

core/modules/system/src/Controller/CsrfTokenController.php, line 14

Namespace

Drupal\system\Controller
View source
class CsrfTokenController implements ContainerInjectionInterface {
    
    /**
     * The CSRF token generator.
     *
     * @var \Drupal\Core\Access\CsrfTokenGenerator
     */
    protected $tokenGenerator;
    
    /**
     * Constructs a new CsrfTokenController object.
     *
     * @param \Drupal\Core\Access\CsrfTokenGenerator $token_generator
     *   The CSRF token generator.
     */
    public function __construct(CsrfTokenGenerator $token_generator) {
        $this->tokenGenerator = $token_generator;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->get('csrf_token'));
    }
    
    /**
     * Returns a CSRF protecting session token.
     *
     * @return \Symfony\Component\HttpFoundation\Response
     *   The response object.
     */
    public function csrfToken() {
        return new Response($this->tokenGenerator
            ->get(CsrfRequestHeaderAccessCheck::TOKEN_KEY), 200, [
            'Content-Type' => 'text/plain',
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CsrfTokenController::$tokenGenerator protected property The CSRF token generator.
CsrfTokenController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
CsrfTokenController::csrfToken public function Returns a CSRF protecting session token.
CsrfTokenController::__construct public function Constructs a new CsrfTokenController object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.