我使用的OAuth2客户端不发送授权:承载,但标准的laravel / passport设置会检查此标头。如何使它与Laravel方面兼容?
答案 0 :(得分:0)
添加以下中间件
<?php
namespace App\Http\Middleware;
class ConvertTokenToBearer
{
/**
* @param \Illuminate\Http\Request $request
* @param $next
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle($request, $next)
{
if ($request->get('access_token')) {
$request->headers->set('Authorization', 'Bearer ' . $request->get('access_token'));
}
$response = $next($request);
return $response;
}
}
并将其添加到您的app / Http / Kernel.php文件中。
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\App\Http\Middleware\ConvertTokenToBearer::class,
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];