Laravel Passport Auth Stuck在同一项目中的自助服务器和客户端上运行时,用于基于密码的令牌认证
的LoginController
public function authenticaterrr(Request $request)
{
$http = new Client();
try{
//dd("Hello");
$response = $http->post(url('oauth/token'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => '2',
'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
// 'username' => $request->get('username'),
// 'password' => $request->get('password'),
'username' => '[email protected]',
'password' => 'xxxxx',
'scope' => '*',
],
]);
// $apiResponse = json_decode((string) $response->getBody(), true);
// dd($apiResponse);
$apiResponse = json_decode((string) $response->getBody(), true);
dd($apiResponse);
session(['api'=> $apiResponse]);
session(['api-token'=> $apiResponse['access_token']]);
return json_decode($response->getBody(), true);
}catch (ClientException $exception){
dd("Hello");
return json_decode($exception->getResponse()->getBody(), true);
}
}
在Web.php中
Route::get('/auth/api/validate', 'Auth\LoginController@authenticaterrr');
在PostMan它没有获得和坚持Here is Output
如果我将创建新项目和使用它比它对我有用那么什么是在同一项目中运行的解决方案
如果您在内置PHP服务器/ php artisan serve
上运行Web应用程序,则第二个auth/token
Passport请求将“杀死”第一个authenticaterrr
HTTP请求。
这是因为内置的PHP服务器是单线程的。
感谢this comment的荣誉。
https://stackoverflow.com/a/51010186/8735680
function tokenRequest(Request $request){
$request->request->add([
"grant_type" => "password",
"username" => $request->username,
"password" => $request->password,
"client_id" => "x",
"client_secret" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
]);
$tokenRequest = $request->create(
env('APP_URL').'/oauth/token',
'post'
);
$instance = Route::dispatch($tokenRequest);
return json_decode($instance->getContent());
}