我遵循了Laracast中提到的确切步骤:Laravel 5.3中的新增功能:Laravel Passportapi authentication使用实现oauth2。
我web.php在客户/消费者项目中的文件如下所示:
use Illuminate\Http\Request;
Route::get('/', function () {
$query = http_build_query([
'client_id' => 2,
'redirect_uri' => 'http://offline.xyz.com/callback',
'response_type' => 'code',
'scope' => '',
]);
return redirect ('http://api.xyz.com/oauth/authorize?'.$query);
});
Route::get('/callback', function (Request $request){
$http= new GuzzleHttp\Client;
$response = $http->post('http://api.xyz.com/oauth/token',[
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 2 ,
'client_secret' => 'tUGYrNeWCGAQt220n88CGoXVu7TRDyZ20fxAlFcL' ,
'redirect_uri' => 'http://offline.xyz.com/callback',
'code' => $request->code,
],
]);
return json_decode((string) $response->getBody(), true);
});
Run Code Online (Sandbox Code Playgroud)
我正在获得权限请求页面,我需要在该页面上authorize允许我的客户端访问api。但是,一旦单击授权,我将被重定向到显示以下消息的页面: …