问题描述
我正在尝试使用Lumen + JWT
在我的API中实现JWT令牌.我正在使用这个 JWT库,我已经设置了它,但是当我想验证使用JWTAuth::attempt($credentials)
我遇到下一个错误
I am trying to implement JWT token in my API using Lumen + JWT
. I am using this JWT Library, I have set up it, but when I want to validate passed using JWTAuth::attempt($credentials)
I get next error
ErrorException in AuthManager.php line 16:
Missing argument 1 for Illuminate\Auth\AuthManager::createDriver(), called in /home/admin/web/mkopilka.ru/public_html/api/referral/vendor/illuminate/support/Manager.php on line 87 and defined
我知道问题出在哪里,但是由于我不太了解框架的内部结构,所以无法弄清楚该如何解决.
I know where is the problem, but cannot figure out how to solve it because I don't know internals of framework well.
我对JWT如何验证用户身份有疑问(检查数据库中的凭据,因为我猜到它使用了jwt.php
中提供的模型类,并带有以下行'user' => 'App\Models\User'
I have question about how does JWT authenticate the user (checks credentials in database, as I can gues it uses model class provided in jwt.php
with the following line 'user' => 'App\Models\User'
默认为'user' => 'App\User'
因此,即使我在此文件中更改了用户模型,我也遇到了下一个错误
So even if I changed user model in this file I got the next error
vendor/illuminate/auth/EloquentUserProvider.php line 126:
Class '\App\User' not found
我认为并决定添加具有后续内容的config/auth.php文件
I thought and decided to add config/auth.php file with succeeding content
return [
'model' => 'App\Models\User'
];
现在我得到第一个例外.
And now I get the the first exception.
出什么问题了,我可以问问我已经覆盖了auth配置文件中的所有参数.
What is wrong I can quess that I have overridden all parameters in auth config file.
Aslo我想知道在哪里可以找到(除了源代码,理解它会花费很多时间)解释JWTAuth::attempt
的工作原理?
Aslo I wonder where can I find (except source code, it will take a lot of time to understand it) explanation how JWTAuth::attempt
works ?
谢谢.
推荐答案
从Laravel 4.1升级到4.2时,我遇到了同样的问题(我认为主要是因为我更新了所有文件并尝试进行作曲家更新之后).
I had the same problem on my upgrade from Laravel 4.1 to 4.2 (I think mainly because I updated all the files and tried to make a composer update afterwards).
对我来说,以下工作有效(如还原相关的更新步骤):
For me the following worked (like reverting the relevant update steps):
将驱动程序,模型和表添加到config/auth.php主数组(另外 到providers子数组中已经存在的一个):
Add driver, model and table to config/auth.php main array (additionally to the already existing one in the providers sub array):
<?php
return [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'users',
// ...
2.添加ArtisanServiceProvider
为防止错误 Artisan:未定义清晰编译的命令,已将Illuminate\Foundation\Providers\ArtisanServiceProvider
读给服务提供商
2. Add ArtisanServiceProvider
To prevent the error Artisan: Command clear-compiled is not defined readd Illuminate\Foundation\Providers\ArtisanServiceProvider
to the service providers
<?php
return [
// ...
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
// ...
3.更新和还原更改
执行更新(composer update
),并通过删除添加的行来还原前两个步骤.
3. Update and revert changes
Perform update (composer update
) and revert the two previous steps by removing the added lines.
这篇关于Illuminate \ Auth \ AuthManager :: createDriver()流明和JWT缺少参数1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!