2016-10-27 4 views
0

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']; 
} 

);

+0

'gen_client' 경로가 아무 것도 반환하지 않으므로'NULL'입니다. 또한,'id' 매개 변수는 사용되지 않습니다. – datashaman

답변

0

gen_client 경로가 아무 것도 반환하지 않으므로 NULL을 반환합니다.

자신 만의 ID을 직접 입력하고 oauth_clients 테이블을 직접 사용하여 혼란 스러울 수도 있습니다.

클라이언트의 ID 및 비밀 를 포함하는 페이로드를 반환합니다 POST/OAuth를/클라이언트를 호출.

는 그런 곳 설정에 그 가치를두고, (당신이 만들고있어 호출에 필요한 다른 매개 변수와 함께)과 같이 사용할 :

[ 
    'client_id' => config('services.myoauth.client_id'), 
    'client_secret' => config('services.myoauth.client_secret'), 
] 

직접 oauth_clients 테이블에 액세스하지 마십시오 , 그게 OAuth 서버의 직업입니다.

OAuth 클라이언트 웹 응용 프로그램을 OAuth 서버에 연결할 때 클라이언트를 만드는 것은 보통 일 때 수동으로 수행됩니다.