vendor/lexik/jwt-authentication-bundle/Security/Authentication/Token/JWTUserToken.php line 32

Open in your IDE?
  1. <?php
  2. namespace Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Token;
  3. use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
  6. if (interface_exists(GuardTokenInterface::class)) {
  7. /**
  8. * Compatibility layer ensuring the guard token interface is applied when available.
  9. *
  10. * @internal
  11. */
  12. abstract class JWTCompatUserToken extends AbstractToken implements GuardTokenInterface
  13. {
  14. }
  15. } else {
  16. /**
  17. * @internal
  18. */
  19. abstract class JWTCompatUserToken extends AbstractToken
  20. {
  21. }
  22. }
  23. /**
  24. * JWTUserToken.
  25. *
  26. * @author Nicolas Cabot <n.cabot@lexik.fr>
  27. */
  28. class JWTUserToken extends JWTCompatUserToken
  29. {
  30. /**
  31. * @var string
  32. */
  33. protected $rawToken;
  34. /**
  35. * @var string
  36. */
  37. protected $providerKey;
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function __construct(array $roles = [], UserInterface $user = null, $rawToken = null, $firewallName = null)
  42. {
  43. parent::__construct($roles);
  44. if ($user) {
  45. $this->setUser($user);
  46. }
  47. $this->setRawToken($rawToken);
  48. if (method_exists($this, 'setAuthenticated')) {
  49. $this->setAuthenticated(true);
  50. }
  51. $this->providerKey = $firewallName;
  52. }
  53. /**
  54. * @param string $rawToken
  55. */
  56. public function setRawToken($rawToken)
  57. {
  58. $this->rawToken = $rawToken;
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function getCredentials()
  64. {
  65. return $this->rawToken;
  66. }
  67. /**
  68. * @deprecated since 2.10, use getFirewallName() instead
  69. */
  70. public function getProviderKey()
  71. {
  72. @trigger_error(sprintf('The "%s" method is deprecated since version 2.10 and will be removed in 3.0. Use "%s::getFirewallName()" instead.', __METHOD__, self::class), E_USER_DEPRECATED);
  73. return $this->getFirewallName();
  74. }
  75. /**
  76. * @return string
  77. */
  78. public function getFirewallName()
  79. {
  80. return $this->providerKey;
  81. }
  82. }