{"action":"closed","issue":{"url":"https://api.github.com/repos/lexik/LexikJWTAuthenticationBundle/issues/212","repository_url":"https://api.github.com/repos/lexik/LexikJWTAuthenticationBundle","labels_url":"https://api.github.com/repos/lexik/LexikJWTAuthenticationBundle/issues/212/labels{/name}","comments_url":"https://api.github.com/repos/lexik/LexikJWTAuthenticationBundle/issues/212/comments","events_url":"https://api.github.com/repos/lexik/LexikJWTAuthenticationBundle/issues/212/events","html_url":"https://github.com/lexik/LexikJWTAuthenticationBundle/issues/212","id":168540949,"number":212,"title":"Entity Provider not working by default","user":{"login":"xavierfaucon","id":6999360,"avatar_url":"https://avatars.githubusercontent.com/u/6999360?v=3","gravatar_id":"","url":"https://api.github.com/users/xavierfaucon","html_url":"https://github.com/xavierfaucon","followers_url":"https://api.github.com/users/xavierfaucon/followers","following_url":"https://api.github.com/users/xavierfaucon/following{/other_user}","gists_url":"https://api.github.com/users/xavierfaucon/gists{/gist_id}","starred_url":"https://api.github.com/users/xavierfaucon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavierfaucon/subscriptions","organizations_url":"https://api.github.com/users/xavierfaucon/orgs","repos_url":"https://api.github.com/users/xavierfaucon/repos","events_url":"https://api.github.com/users/xavierfaucon/events{/privacy}","received_events_url":"https://api.github.com/users/xavierfaucon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lexik/LexikJWTAuthenticationBundle/labels/Bug","name":"Bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-31T22:08:10Z","updated_at":"2016-08-04T22:00:24Z","closed_at":"2016-08-04T22:00:24Z","body":"Hello,\r\n\r\nI am using LewikJwtBundle with Symfony 2.8.*.\r\n\r\nI have implemented a custom User Entity (not FOSUserBundle) (following this:\r\nhttp://symfony.com/doc/current/security/entity_provider.html) with username OR email login. It works correctly without LexikJwtBundle as per the official doc. However with LexikJwt it returned 401 everytime. The solution was to create a custom user provider. It could be worth mentionning in the doc?\r\n\r\nDefault test which wasn't working:\r\n```\r\n// src/AppBundle/Entity/UserRepository.php\r\nnamespace AppBundle\\Entity;\r\n\r\nuse Symfony\\Bridge\\Doctrine\\Security\\User\\UserLoaderInterface;\r\nuse Doctrine\\ORM\\EntityRepository;\r\n\r\nclass UserRepository extends EntityRepository implements UserLoaderInterface\r\n{\r\n    public function loadUserByUsername($username)\r\n    {\r\n        return $this->createQueryBuilder('u')\r\n            ->where('u.username = :username OR u.email = :email')\r\n            ->setParameter('username', $username)\r\n            ->setParameter('email', $username)\r\n            ->getQuery()\r\n            ->getOneOrNullResult();\r\n    }\r\n}\r\n```\r\nand\r\n\r\n```\r\n# app/config/security.yml\r\nsecurity:\r\n    # ...\r\n\r\n    providers:\r\n        our_db_provider:\r\n            entity:\r\n                class: AppBundle:User\r\n```\r\n\r\n\r\nThen afterjust creating a custom user provider in the same fashion as the one FOSUserBundle: (http://symfony.com/doc/current/security/custom_provider.html) it worked properly.\r\n\r\n\r\n```\r\n<?php\r\n\r\n\r\nnamespace UserBundle\\Security\\User;\r\n\r\nuse Symfony\\Component\\Security\\Core\\User\\UserProviderInterface;\r\nuse Symfony\\Component\\Security\\Core\\User\\UserInterface;\r\nuse Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException;\r\nuse Symfony\\Component\\Security\\Core\\Exception\\UnsupportedUserException;\r\n\r\nclass EmailUserProvider implements UserProviderInterface\r\n{\r\n    protected $userManager;\r\n\r\n    public function __construct($userManager)\r\n    {\r\n        $this->userManager = $userManager;\r\n    }\r\n\r\n    public function loadUserByUsername($username)\r\n    {\r\n        $user = $this->userManager->getUserByUsernameOrEmail($username);\r\n\r\n        if (!$user) {\r\n            throw new UsernameNotFoundException(sprintf('Username \"%s\" does not exist.', $username));\r\n        }\r\n        \r\n        return $user;\r\n    }\r\n\r\n    public function refreshUser(UserInterface $user)\r\n    {\r\n        if (!$user instanceof User) {\r\n            throw new UnsupportedUserException(\r\n                sprintf('Instances of \"%s\" are not supported.', get_class($user))\r\n            );\r\n        }\r\n\r\n        return $this->loadUserByUsername($user->getUsername());\r\n    }\r\n\r\n    public function supportsClass($class)\r\n    {\r\n       return $class === 'UserBundle\\Entity\\User';\r\n    }\r\n}\r\n```"}}
{"actor":{"display_login":"chalasr"}}