私は、laravel 5.3の新しいoauth2機能を使用して、私のlaravelプロジェクトの1つから別のプロジェクトにapi呼び出しをしようとしています。'auth:api'ミドルウェアを追加した後にルートが見つかりません。Laravel 5.3
私は古いものから呼び出したい私の新しいlaravelプロジェクトのapi.phpルートファイルでこのルートを持っている:で、私は問題なく、それを呼び出すことができますミドルウェアなしで
Route::get('/hello', function() {
return 'hello';
})->middleware('auth:api');
ミドルウェアでは、404が見つかりませんでした。
$http = new GuzzleHttp\Client;
$response = $http->post('http://my-oauth-project.com/oauth/token', [
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => 'client_id',
'client_secret' => 'client_secret',
],
]);
$token = json_decode($response->getBody(), true)['access_token'];
$response = $http->get('http://my-oauth-project.com/api/hello', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
],
]);
return $response->getBody();
返されるエラー:
[2016-10-14 09:46:14] local.ERROR: exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `GET http://my-oauth-project.com/api/hello` resulted in a `404 Not Found` response:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow (truncated...)
私は、ドキュメントが使用すると言っているミドルウェアは、ドキュメントが広範囲にカバーするもの(クライアントの信用とパスワードの付与)で壊れてしまうとは思いません。それにもかかわらず、これを見つけてくれてありがとう! – samrap