I made exactly the answer from this post , but the token property is null, and the user is correctly registered and the route is behind the firewall. In addition, I am embedding SecurityContext in other services and it is working fine.
services.xml:
<service id="tc.extensions.relation_helper" class="TC\CoreBundle\Extensions\RelationHelperExtension"> <argument type="service" id="security.context" /> <tag name="twig.extension" /> </service>
My extension:
class RelationHelperExtension extends Twig_Extension { private $user; public function __construct(SecurityContext $securityContext){ $this->user = $securityContext->getToken()->getUser(); }
source share