在我的客户中,我使用以下路线来获取身份验证令牌。
Route::get('/redirect', function () {
$query = http_build_query([
'client_id' => '1',
'redirect_uri' => 'http://localhost:8001/callback',
'response_type' => 'code',
'scope' => ''
]);
return redirect('http://localhost:8000/oauth/authorize?'.$query);
});
Route::get('/callback', function (Illuminate\Http\Request $request) {
$http = new \GuzzleHttp\Client;
$response = $http->post('http://localhost:8000/oauth/token', [
'form_params' => [
'client_id' => '1',
'client_secret' => 'secret-code',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://localhost:8001/callback',
'code' => $request->code,
],
]);
return json_decode((string) $response->getBody(), true);
});
但是当我浏览 http://localhost:8001/redirect时,它会询问 http 身份验证。为什么需要身份验证以及如何解决?