Skip to content

Token was deauthenticated Error Symfony 4 #9914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ with the following fields: ``id``, ``username``, ``password``,

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;

/**
* @ORM\Table(name="app_users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User implements UserInterface, \Serializable
class User implements UserInterface, \Serializable, EquatableInterface
{
/**
* @ORM\Column(type="integer")
Expand Down Expand Up @@ -108,7 +109,7 @@ with the following fields: ``id``, ``username``, ``password``,
public function eraseCredentials()
{
}

/** @see \Serializable::serialize() */
public function serialize()
{
Expand All @@ -130,7 +131,27 @@ with the following fields: ``id``, ``username``, ``password``,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized, ['allowed_classes' => false]);
) = unserialize($serialized, ['allowed_classes' => false]);
}

/**
* if you want to keep the control on what attributes are compared at each request to know if user have changed,
* you can implement Equatable interface and the method isEqualTo and add all attributes you want compare.
* The equality comparison should neither be done by referential equality
* nor by comparing identities (i.e. getId() === getId()).
*
* However, you do not need to compare every attribute, but only those that
* are relevant for assessing whether re-authentication is required.
*
* @return bool
*/
public function isEqualTo(UserInterface $user)
{
if ($this->password !== $user->getPassword()) {
return false;
}

return true;
}
}

Expand Down