【发布时间】:2019-11-07 02:14:46
【问题描述】:
我正在研究 laravel 护照包。当我撤销令牌并访问经过身份验证的端点时,它会引发异常。
日志文件包含“资源所有者或授权服务器拒绝请求”。要处理的是异常,我创建了 OAuth 中间件并在其中放置了异常代码,如此链接中所述: https://www.kingpabel.com/oauth2-exception-custom-error-message/
public function handle($request, Closure $next)
{
//return $next($request);
try {
$response = $next($request);
// Was an exception thrown? If so and available catch in our middleware
if (isset($response->exception) && $response->exception) {
throw $response->exception;
}
return $response;
} catch (OAuthException $e) {
$data = [
// 'error' => $e->errorType,
// 'error_description' => $e->getMessage(),
'error' => 'Custom Error',
'error_description' => 'Custom Description',
];
return \Response::json($data, $e->httpStatusCode, $e->getHttpHeaders());
}
}
我想以 json 格式返回错误,例如:
{
"error": "Token is invalid!"
}
如果有人在这方面指导我,我将不胜感激。 谢谢,
【问题讨论】:
标签: laravel exception oauth laravel-passport