Laravel 5.3에서 Passport Authentication API를 사용하고 있습니다. oauth 클라이언트를 생성하기위한 두 개의 라우트와 access_token 요청을위한 두 개의 라우트를 작성했습니다. 하지만 /redirect
경로에서 /gen_client
경로와 로그인 페이지를 보여주는 NULL 값을 얻고 있습니다.Lautvel 클라이언트 생성 및 Laravel Passport의 코드를 통한 액세스 토큰 요청에 문제가 발생했습니다.
누구든지 나를 도와 줄 수 있습니까?
Route::get('/gen_client', function() {
$http = new GuzzleHttp\Client();
$response = $http->post(url('/') . '/oauth/clients', [
'form_params' => [
'id' => '[email protected]',
'name' => 'OK',
'redirect' => url('/') . '/callback'
],
]);
$response_body = json_decode((string)$response->getBody(), true);
var_dump($response_body);
});
Route::get('/redirect', function() {
$oauth_client = DB::table('oauth_clients')->where('id', '=', '[email protected]')->first();
$query = http_build_query([
'client_id' => $oauth_client->id,
'redirect_uri' => $oauth_client->redirect,
'response_type' => 'code',
'scope' => '',
]);
return redirect(url('/') . '/oauth/authorize?'.$query);
});
Route::post('callback', function (Request $request) {
$http = new GuzzleHttp\Client();
$oauth_client = DB::table('oauth_clients')->where('id', '=', '[email protected]')->first();
$response = $http->post(url('/') . '/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => $oauth_client->id,
'client_secret' => $oauth_client->secret,
'redirect_uri' => url('/') . '/callback',
'code' => $request->code,
],
]);
$response_body = json_decode((string)$response->getBody(), true);
var_dump($response_body);
$access_token = $response_body['access_token'] ;
$refresh_token = $response_body['refresh_token'];
}
);
'gen_client' 경로가 아무 것도 반환하지 않으므로'NULL'입니다. 또한,'id' 매개 변수는 사용되지 않습니다. – datashaman