JSON Web Token only work in Laravel with Eloquent model

Solution:

  1. Yes, you can:

 

use App\Entities\User;
use Doctrine\ORM\EntityManagerInterface;
use Tymon\JWTAuth\Providers\User\UserInterface;

class DoctrineUserAdapter implements UserInterface
{
    protected $em;

    public function __construct(User $user, EntityManagerInterface $em)
    {
        $this->em = $em;
    }

    public function getBy($key, $value)
    {
        return $this->em->find('App\Entities\User', $value);
    }
}

You can inject EntityManagerInterface object as a second parameter, first parameter is a User model type from ‘providers.user’ in jwt.php configuration, why? Look at the code in JWTAuthServiceProvider.php:

/**
 * Register the bindings for the User provider.
 */
protected function registerUserProvider()
{
    $this->app['tymon.jwt.provider.user'] = $this->app->share(function ($app) {
        return $app->make($this->config('providers.user'), [$app->make($this->config('user'))]);
    });
}

My simple user model:

 

use DOctrine\ORM\Mapping as ORM;

/**
 * Users *
 * @ORM\Table(name="users")
 * @ORM\Entity
 */
class User implements \Illuminate\Contracts\Auth\Authenticatable
{
    use \LaravelDoctrine\ORM\Auth\Authenticatable;

    /**
     *
     * @var integer *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
     public $id;
}
  1. You can do this in version 1.0.0. More about problem: https://github.com/tymondesigns/jwt-auth/issues/343