mjp*_*r11 5 authentication laravel passport.js axios
我看过很多关于这个错误的帖子,但没有一个解决方案对我有用。
我正在使用 Passport 运行 Laravel,它在我的开发服务器上运行良好。正如预期的那样,当尝试检查用户是否在我的开发服务器上通过身份验证时,它返回捕获(在 axios 调用中):
开发服务器
"message":"Unauthenticated."
Run Code Online (Sandbox Code Playgroud)
但是,在我的生产服务器上运行相同的代码时,它返回捕获:
生产服务器:
"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token'
in 'where clause' (SQL: select * from `users` where `api_token` = ...
Run Code Online (Sandbox Code Playgroud)
我已经运行了 Passport 迁移,并且在 config/auth.php 中将 ['guards']['api']['driver'] 设置为 Passport,并更新了显然为其他人解决了问题的配置缓存。
看起来身份验证需要使用护照迁移中的 oauth 表,但查询似乎正在查看用户表。
编辑:
我能够确定我的开发服务器使用RequestGuard该类来查找用户,而我的生产服务器使用TokenGuard该类来查找用户。
Zia*_*man 22
我遇到了同样的问题。我正在使用 Laravel Passport。这一切都与配置有关。config/auth.php在guards数组中获取并将api数组的驱动程序名称更改为passport
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',//instead of token
'provider' => 'users',
'hash' => false,
],
],
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,我已经解决了这个问题
php artisan config:clear
php artisan config:cache
php artisan cache:clear
Run Code Online (Sandbox Code Playgroud)
可能有帮助
尽管存在令人困惑的错误,但我按照本文中的步骤操作,现在它可以正确地通过 RequestGuard 路由身份验证请求,并且身份验证按预期进行。
不知道缓存是如何混乱导致这种情况的,但我猜测我的配置缓存被困在 web 防护上,也许清除它现在可以通过 api 防护正确路由。
希望这对其他人有帮助。
| 归档时间: |
|
| 查看次数: |
11431 次 |
| 最近记录: |