我正在尝试设置我的api验证访问令牌。 我按照https://laravel.com/docs/5.8/passport上的文档设置了Passport。 我正在与邮递员进行测试。
当我执行登录时,我将获得访问令牌。 问题是,当我尝试在auth:api中间件下进行路由时,似乎无法控制,即使我未设置令牌头,它们也能正常工作。
config / auth.php
tripleee@debian$ cat >test.msg
From: Name Lastname <address9@gmail.com>
Date: Wed, 12 Jun 2019 20:37:17 +1200
Message-ID<CADxD3vdy5cW55mogOK5+543ngU7iFKjJcpDV3Q4YL772F=LdQ@mail.gmail.com>
Subject:
No fooling
^D
tripleee@debian$ cat >test.rc
SHELL=/bin/sh
DEFAULT=/dev/null
VERBOSE=yes
:0 fhw
* ^From.*address9\@gmail\.com
* ^Subject:\/.+
| /usr/bin/formail -i "Subject: [New Report]$MATCH"
^D
tripleee@debian$ procmail -m test.rc <test.msg
procmail: [3717] Wed Jun 12 13:38:55 2019
procmail: Match on "^From.*address9\@gmail\.com"
procmail: Assigning "MATCH="
procmail: Matched " "
procmail: Match on "^Subject:\/.+"
procmail: Executing " /usr/bin/formail -i "Subject: [New Report]$MATCH""
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
From address9@gmail.com Wed Jun 12 13:38:55 2019
Subject: [New Report]
Folder: /dev/null 253
AuthServiceProvider.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
// 'hash' => false,
],
],
routes / api.php
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
//
}
}
Http \ Controllers \ Auth \ AuthController.php
Route::group([
'prefix' => 'auth'
], function () {
Route::post('login', 'Auth\AuthController@login')->name('login');
Route::post('register', 'Auth\AuthController@register');
Route::group([
'middleware' => 'auth:api'
], function() {
Route::get('logout', 'Auth\AuthController@logout');
Route::get('user', 'Auth\AuthController@user');
Route::get('getdata', array('uses' => 'DataController@getData' ));
});
});
因此,如果我登录,我将获得访问令牌
如果我不带标题就调用/ api / auth / getadata,它将无法控制。
如果我尝试获取用户,则为空{}
我希望在理解正确流程方面获得帮助。 谢谢。