vendor/symfony/security-http/Authenticator/Passport/Badge/CsrfTokenBadge.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Http\Authenticator\Passport\Badge;
  11. use Symfony\Component\Security\Http\EventListener\CsrfProtectionListener;
  12. /**
  13. * Adds automatic CSRF tokens checking capabilities to this authenticator.
  14. *
  15. * @see CsrfProtectionListener
  16. *
  17. * @author Wouter de Jong <wouter@wouterj.nl>
  18. *
  19. * @final
  20. */
  21. class CsrfTokenBadge implements BadgeInterface
  22. {
  23. private $resolved = false;
  24. private $csrfTokenId;
  25. private $csrfToken;
  26. /**
  27. * @param string $csrfTokenId An arbitrary string used to generate the value of the CSRF token.
  28. * Using a different string for each authenticator improves its security.
  29. * @param string|null $csrfToken The CSRF token presented in the request, if any
  30. */
  31. public function __construct(string $csrfTokenId, ?string $csrfToken)
  32. {
  33. $this->csrfTokenId = $csrfTokenId;
  34. $this->csrfToken = $csrfToken;
  35. }
  36. public function getCsrfTokenId(): string
  37. {
  38. return $this->csrfTokenId;
  39. }
  40. public function getCsrfToken(): ?string
  41. {
  42. return $this->csrfToken;
  43. }
  44. /**
  45. * @internal
  46. */
  47. public function markResolved(): void
  48. {
  49. $this->resolved = true;
  50. }
  51. public function isResolved(): bool
  52. {
  53. return $this->resolved;
  54. }
  55. }