嘿,我在我的prod网站上有个问题,想用Laravel护照登录。它说我的Lcobucci JWT解析器是不可实例化的。它在本地工作,但在我的遥控器上不起作用。
我怎么解决这个问题?
错误:
exception: "Illuminate\Contracts\Container\BindingResolutionException"
file: "/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php"
line: 1038
message: "Target [Lcobucci\JWT\Parser] is not instantiable while building [Laravel\Passport\PersonalAccessTokenFactory]."
trace: [,…]
登录控制器方法:
public function login(Request $request) {
$login = $request->validate([
'email' => 'required:string',
'password' => 'required:string'
]);
if(filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
//user sent their email
Auth::attempt(['email' => $request->email, 'password' => $request->password]);
} else {
//they sent their username instead
Auth::attempt(['username' => $request->email, 'password' => $request->password]);
}
if(!Auth::check()) {
return response([
'status' => 'fail',
'message' => 'Invalid credentials'
]);
}
$accessToken = Auth::user()
->createToken('authToken')
->accessToken;
return response([
'status' => 'success',
'user' => new User_Resource(Auth::user()),
'access_token' => $accessToken
]);
}
发布于 2020-11-26 07:39:48
我也遇到了同样的问题,在您的项目composer.json中添加"lcobucci/jwt":"3.3.3“并执行composer更新。我在https://github.com/laravel/passport/issues/1381上找到了这个解决方案。
发布于 2021-04-16 12:16:57
Laravel:"8“和Lcobucci\JWT:"^3.4"
解决方案:
use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Token\Parser;
.
.
...
public function GetTokenId(Request $request)
{
// Get the Access_Token from the request
$Token = $request->bearerToken();
// Parse the Access_Token to get the claims from them the jti(Json Token Id)
$TokenId = (new Parser(new JoseEncoder()))->parse($token)->claims()
->all()['jti'];
return $tokenId;
}
发布于 2022-07-15 05:47:02
如果有人仍然收到此错误,那是因为$verifiedIdToken->getClaim('sub')
在3.4中被弃用,在4.0中被删除。使用$verifiedIdToken->claims()->get('sub')
这个insted。
https://stackoverflow.com/questions/65014655
复制相似问题