Laravel 接入 jwt-auth 时一个疑似插件问题的报错?
在用laravel-v5.6.28
接入插件"tymon/jwt-auth":1.0.0-rc.2
时
按照常规步骤接入,一切OK,最后通过Post慢进行接口测试时报错
我故意没有在Authorization里面选择Type。原本应该使用Bearer Token验证,这里我留空了。
报错内容:
Argument 1 passed to Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException::__construct() must be of the type string, null given, called in /......./vendor/dingo/api/src/Auth/Auth.php on line 113
查看这行代码
protected function throwUnauthorizedException(array $exceptionStack)
{
$exception = array_shift($exceptionStack);
if ($exception === null) {
$exception = new UnauthorizedHttpException(null, 'Failed to authenticate because of bad credentials or an invalid authorization header.');
}
throw $exception;
}
不怎么会用markdown将就看下吧】
$exception = new UnauthorizedHttpException(null, 'Failed to authenticate because of bad credentials or an invalid authorization header.');
是报错的行数,正常来讲这里应该抛出一个401的异常,并附带message“Failed to authenticate because of bad credentials or an invalid authorization header.”才对,但是却抛出了一个500的异常,Argument 1 passed to UnauthorizedHttpException::__construct() must be of the type string, null given.
通过UnauthorizedHttpException这个类可以看到,
namespace Symfony\Component\HttpKernel\Exception;
class UnauthorizedHttpException extends HttpException
{
public function __construct(string $challenge, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = array())
{
$headers['WWW-Authenticate'] = $challenge;
parent::__construct(401, $message, $previous, $headers, $code);
}
}
____ construct 方法的第一个参数规定为string格式,但Auth.php传的时候是null,这里应该是框架和插件冲突了吧?还是其他什么问题?
有大佬能帮我解答一下嘛?
推荐文章: