我在我的laravel 5.0.35应用上设置了JWT(tymondesigns/jwt-auth
)。身份验证很有效。但是,当我使用jwt.auth
中间件时,会出现错误:exception 'ReflectionException' with message 'Class Tymon\JWTAuth\MiddlewareGetUserFromToken does not exist'
您的帮助将不胜感激)))以下文件可能对您有所帮助:
app.php
$providers = [
// other records
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider',
];
'aliases' => [
// other records
'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth',
'JWTFactory' => 'Tymon\JWTAuth\Facades\JWTFactory'
];
kernel.php
protected $routeMiddleware = [
'auth' => 'App\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
'jwt.auth' => 'Tymon\JWTAuth\MiddlewareGetUserFromToken',
'jwt.refresh' => 'TymonJWTAuth\MiddlewareRefreshToken'
];
我称之为jwt.auth
中间件
namespace App\Http\Controllers\Resources;
use IlluminateHttpRequest;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use App\User;
use PDO;
use Log;
class DirectionsController extends Controller {
public function __construct()
{
$this->middleware('jwt.auth');
}
compsoser.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"guzzlehttp/guzzle": "~6.0",
"rap2hpoutre/laravel-log-viewer": "0.2.*",
"irazasyed/telegram-bot-sdk": "^2.0",
"tymon/jwt-auth": "0.5.*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
答案 0 :(得分:5)
我发现了错误。错误是kernel.php
中存在中间件声明的地方'jwt.auth' => 'Tymon\JWTAuth\MiddlewareGetUserFromToken',
'jwt.refresh' => 'TymonJWTAuth\MiddlewareRefreshToken'
因此,MiddlewareGetUserFromToken
应该是Middleware\GetUserFromToken
而不是<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
。看起来这种类型是在我复制它的博客文章中。当你从其他网站复制代码时要小心)