Search code examples
phpsymfonysymfony4

Undefined method isGranted in Symfony 4


I am using a statement from a Symfony2 app in Symfony4:

$securityContext = $this->container->get('security.token_storage');         
if($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') ){
. . .
}

I get always error:

Attempted to call an undefined method named "isGranted" of class "Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage

what I am missing?


Solution

  • Symfony gives you several ways to enforce authorization, including […] using isGranted on the security.authorization_checker service directly.

    source

    You should call isGranted on the security.authorization_checker service, not the security.token_storage.