Laravel 护照授权

问题描述 投票:0回答:1

我正在尝试使用 Laravel 和 Laravel/Passport 设置 SSO,但遇到了问题。 /oauth/authorize 路由为无效客户端返回 JSON,为有效客户端返回视图(授权页面)。难道我做错了什么?对于这些情况,返回两个视图或两个 JSON 不是很正常吗?

我创建了一个新的 laravel 应用程序,安装了 laravel/passport,使用命令 php artisan Passport:client 创建一个客户端并调用该页面 http://localhost:8000/oauth/authorize?client_id=&redirect_uri=http%3A%2F%2Flocalhost%2Fauth%2Fcallback&response_type=code&scope= 对于有效的客户端 ID,我收到授权页面,但对于无效的客户端 ID,我收到 json。 我希望在这两种情况下都能接收 html 页面,或者如果 header 接受 application/json 则接收有效/无效客户端的 json。

laravel client single-sign-on laravel-passport authorize
1个回答
0
投票
use Laravel\Passport\Exceptions\OAuthServerException;

public function render($request, Throwable $exception){
if ($exception instanceof OAuthServerException) 
{
 return response()->view('errors.oauth', [], 500);
}
 return parent::render($request, $exception);
}

将此代码添加到您的 Exceptions/Handler.php 中

可能有帮助

© www.soinside.com 2019 - 2024. All rights reserved.