【发布时间】:2026-01-21 21:00:02
【问题描述】:
我正在尝试通过 oauth/authorize 使用 Passport,以允许 Web 应用程序稍后获取代码和请求令牌,但出现错误
路由 [登录名] 未定义
下面是我的代码。
客户端代码
// First route that user visits on consumer app
Route::get('/', function () {
// Build the query parameter string to pass auth information to our request
$query = http_build_query([
'client_id' => 3,
//'client_secret' => 'MtkEmBL0f0Bf4LcEPcOBUS0wLHvF5xqqchhCpaTH',
'redirect_uri' => 'http://client.app:8082/callback',
'response_type' => 'code',
'scope' => ''
]);
// Redirect the user to the OAuth authorization page
return redirect('http://server.app:8082/oauth/authorize?' . $query);
});
// Route that user is forwarded back to after approving on server
Route::get('/callback', function (Request $request) {
return 'test 2';
$http = new GuzzleHttp\Client;
$response = $http->post('http://server.app:8082/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 3, // from admin panel above
'client_secret' => 'MtkEmBL0f0Bf4LcEPcOBUS0wLHvF5xqqchhCpaTH', // from admin panel above
'redirect_uri' => 'http://client.app:8082/callback',
'code' => $request->code // Get code from the callback
]
]);
// echo the access token; normally we would save this in the DB
return json_decode((string) $response->getBody(), true)['access_token'];
});
【问题讨论】:
-
你在哪里定义认证路由?
-
嗨舒克申!我的路线在 AuthServiceProvider 文件中定义,如下所示.. Passport::routes();
-
问题,你在哪里定义了/oauth/authorize 路由?我将 oneAuth 客户端用于更复杂的场景,但这部分流程也适用于我的案例
标签: php laravel oauth-2.0 laravel-passport