我已经按照官方文档(
https://laravel.com/docs/5.3/passport#introduction)中的描述为Laravel 5.3设置了Laravel Passport包.
我希望API由移动应用程序使用,因此我尝试实现密码授予令牌.我创建了一个密码授予客户端,以及令牌请求进程……
$response = $http->post('http://my-app.com/oauth/token',[ 'form_params' => [ 'grant_type' => 'password','client_id' => 'client-id','client_secret' => 'client-secret','username' => 'my@email.com','password' => 'my-password','scope' => '',],]);
…按预期工作,为我的一个用户返回访问令牌和刷新令牌.
一方面,
PHP artisan route:list
列出api / user URI的正确中间件:api,auth:api
api guard的驱动程序在config / auth.PHP中正确设置为passport.
总而言之,安装过程的每一步都已完成(https://laravel.com/docs/5.3/passport#installation).
Route::get('/user',function (Request $request) { return $request->user(); })->middleware('auth:api');
当我访问http://my-app.com/api/user时出现问题,因为它似乎是使用’web’中间件验证请求,而不是’api’…
当我访问时,如果用户未登录,我将被重定向到/ login(登录表单),如果是…则重定向到/ home
任何帮助将非常感激.
提前致谢.