首页 > 解决方案 > 如何检查护照个人令牌是否已过期或被撤销?

问题描述

我正在使用 Laravel 作为我的反应应用程序的后端 API。如果令牌已过期或已撤销访问权限,我想返回错误消息。但是,在我的 Authenticate 中间件上,我只能捕获 AuthenticationException。此异常仅返回消息“未验证”。下面是我当前在 Authenticate 中间件中的代码

public function handle($request, Closure $next, ...$guards) {
    try {
        $this->authenticate($request, $guards);
    } catch (AuthenticationException $e) {
        $data['token'] = false;

        return ResponseServices::error(__('Auth.token_expired', []))
            ->data($data)
            ->toJson();
    }

    return $next($request);
}

我尝试使用 OAuthServerException 和 Throwable 捕获异常,但无法捕获它。只能捕获 AuthenticationException。

但是,如果我在可报告函数的处理程序类中 dd Throwable,我能够获取此信息在此处输入图像描述

是否可以在我的中间件中获取提示消息?

标签: phplaraveloauth-2.0laravel-passport

解决方案


推荐阅读