Laravel Passport-/oauth/token生成无效令牌 [英] Laravel Passport - /oauth/token generates invalid token
问题描述
因此,我使用 php artisanpassport:client
创建了一个客户端,当我对auth/token进行POST请求时,幸好取回了一个令牌.
So I created a client using php artisan passport:client
, and when I do a POST request to oauth/token I thankfully get back a token.
但是,当我尝试通过将其放在标头中并转到受 auth:api
保护的路由来使用该令牌时,遭到未经授权的401.
However, when I try to use that token by putting it in my headers and going to an auth:api
protected route I get 401 unauthorized.
但是,使用其他登录路径似乎可行.当我在api控制器中使用此路由时:
Using a different route to login, however, seems to work. When I use this route in my api controller:
Route::post('/login', 'Auth\LoginController@login')->name('login');
具有以下代码:
public function login(Request $request) {
$input = $request->all();
if (Auth::attempt(['email' => $input['email'], 'password' => $input['password'] ])) {
$user = Auth::user();
return [
'success' => true,
'token' => $user->createToken('test')->accessToken
];
}
return [
'success' => false,
'message' => 'unable to authenticate'
];
}
我找回了一个在受保护的路由上工作的令牌.
I get back a token that works on protected routes.
我正在使用Postman进行测试,我有标头 Authorization:Bearer< token>
和 Accept:application/json
.不知道为什么它会以一种方式起作用,而不能以另一种方式起作用.
I'm using Postman to test, I have headers Authorization: Bearer <token>
and Accept: application/json
. Not sure why it works one way but not another.
这是受保护的路线:
Route::middleware('auth:api')->get('/user', function (Request $request)
{
return $request->user();
});
使用:
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
推荐答案
就我而言,从WHM服务器和功能中删除Lsapi组件.
In my case remove the Lsapi component from WHM server and function.
这篇关于Laravel Passport-/oauth/token生成无效令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!