私はhttps://github.com/tymondesigns/jwt-authを使用しています。ここでTymon JWTの代わりにデータベースプロバイダを使用して
は、私がインストールする方法についてのチュートリアルを読んだ私のcomposer.json
"laravel/lumen-framework": "5.3.*",
"tymon/jwt-auth": "^[email protected]",
です。そのうちのいくつかは以下のとおりです。https://laravelista.com/posts/json-web-token-authentication-for-lumen
https://scotch.io/tutorials/role-based-authentication-in-laravel-with-jwt
- は、私はそれが私の地元に取り組み、成功したトークンを返す作ることができています。しかし、問題は、
database.sqlite
からデータを取得するプロバイダに雄弁を使用する代わりに、私のドライバとしてデータベースを使いたいということです。それと、私はそれが今でデータベーススルー接続であるので、それは今私もいくつかのコードを変更する必要があり
DatabaseUserProvider.php
を使用して、私の
config/auth.php
に
'providers' => [ 'users' => [ 'driver' => 'database', 'table' => 'user_table', // 'driver' => 'eloquent', // 'model' => App\User::class, ], ],
を設定しています。
/** * 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())); }
パスワードを検証するときに
app('hash')->make()
を追加したことに注目してください。次に、取得したユーザーを
GenericUser
オブジェクトに挿入します。/** * 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); } }
それは
GenericUser
オブジェクト上にあるので、それはのエラー与える:この問題を解決するためにArgument 1 passed to Tymon\JWTAuth\JWT::fromUser() must be an instance of Tymon\JWTAuth\Contracts\JWTSubject, instance of Illuminate\Auth\GenericUser given
を、私は下のすべての方法に
JWTSubject
注入を除去することによって、それを「ハック」する必要がありますtymon\jwt-auth\src\JWT.php
これをクリーニングするより良い方法はありますか?