Tymon JWT使用数据库提供程序代替eloquent

I'm using https://github.com/tymondesigns/jwt-auth on my lumen application.

Here's my composer.json

"laravel/lumen-framework": "5.3.*",
"tymon/jwt-auth": "^1.0@dev",

I've read a of tutorials on how to install. Some of which are:

I am able to make it work on my local and successfully return the token. But the problem is that instead of using eloquent on the provider that fetches data from database.sqlite, I want to use database as my driver.

With that, I have set

'providers' => [
    'users' => [
        'driver' => 'database',
        'table'  => 'user_table',
        // 'driver' => 'eloquent',
        // 'model' => App\User::class,
    ],
],

on my config/auth.php

Since it is now connection thru a database, it now uses the DatabaseUserProvider.php

I need to modify some codes though.

/**
 * Validate a user against the given credentials.
 *
 * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
 * @param  array  $credentials
 * @return bool
 */
public function validateCredentials(UserContract $user, array $credentials)
{
    $plain = $credentials['password'];

    return $this->hasher->check($plain, app('hash')->make($user->getAuthPassword()));
}

Notice that I added a app('hash')->make() when validating the password.

It then inject the retrieved user into the GenericUser object.

/**
 * Get the generic user.
 *
 * @param  mixed  $user
 * @return \Illuminate\Auth\GenericUser|null
 */
protected function getGenericUser($user)
{
    if (! is_null($user)) {
        return new GenericUser((array) $user);
    }
}

Since it is on the GenericUser object, it gives an error of:

Argument 1 passed to Tymon\JWTAuth\JWT::fromUser() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of Illuminate\Auth\GenericUser given

In order to fix this, I have to "hack" it by removing the JWTSubject injection on every method under the tymon\jwt-auth\src\JWT.php

Is there a better way to clean this up?

You can easily fix it by making your authenticating user implement JWTSubject, which is the most right thing to do.

class GenericUser implements JWTSubject {
    [...]
}

But, since you're dealing with a Laravel native implementation, I'd suggest you to extend it and implement JWTSubject, instead of going everywhere in jwt-auth's code and remove the type-hints.