0
我的API已建成Laravel 5.4護照,授權和發行的訪問令牌是否工作正常,但與資源處理類似下面用失眠或郵差時:Laravel護照API返回的異常爲HTML而不是JSON響應
Authorization: Bearer [encrypted access token goes here which has only "manage-users" scope]
Content-Type: application/json
Accept: application/json
我上述要求發送到這個網址:
這已經restric泰德訪問該求助於令牌具有這種作用域
管理用戶,測試範圍-1
Route::get('/users', [
'as' => 'users',
'uses' => '[email protected]'
])->middleware(['auth:api', 'scopes:manage-users,test-scope-1']);
範圍已在被定義:
AuthServiceProvider
Passport::tokensCan([
'manage-users' => 'testing',
'test-scope-1' => 'test scope',
'test-scope-2' => 'another test scope',
]);
protected $routeMiddleware = [
...,
...,
...,
'scopes' => \Laravel\Passport\Http\Middleware\CheckScopes::class,
'scope' => \Laravel\Passport\Http\Middleware\CheckForAnyScope::class
];
用於授權此請求的令牌僅具有「manage-users」作用域,因此除了訪問此資源所需的作用域「test-scope-1」之外,我還希望獲得包含未授權訪問的json響應401 」。
雖然我得到了一個HttpException「提供了無效的作用域」。作爲HTML響應不JSON
編輯 Auth-Scaffolding is not installed.