class DeprecatedCsrfTokenController

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/csrf_test/src/Controller/DeprecatedCsrfTokenController.php \Drupal\csrf_test\Controller\DeprecatedCsrfTokenController

Returns responses for Deprecated CSRF token routes.

This controller tests using the deprecated CSRF token key 'rest'.

@todo Remove this before drupal:10.0.0 https://www.drupal.org/node/3115308

Hierarchy

Expanded class hierarchy of DeprecatedCsrfTokenController

See also

\Drupal\Core\Access\CsrfRequestHeaderAccessCheck::access()

File

core/modules/system/tests/modules/csrf_test/src/Controller/DeprecatedCsrfTokenController.php, line 19

Namespace

Drupal\csrf_test\Controller
View source
class DeprecatedCsrfTokenController 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 using the deprecated 'rest' value protecting session token.
     *
     * @return \Symfony\Component\HttpFoundation\Response
     *   The response object.
     */
    public function csrfToken() {
        return new Response($this->tokenGenerator
            ->get('rest'), 200, [
            'Content-Type' => 'text/plain',
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DeprecatedCsrfTokenController::$tokenGenerator protected property The CSRF token generator.
DeprecatedCsrfTokenController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
DeprecatedCsrfTokenController::csrfToken public function Returns a CSRF using the deprecated 'rest' value protecting session token.
DeprecatedCsrfTokenController::__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.