首页 > 解决方案 > 使用 laravel-passport 进行 Swagger API 身份验证

问题描述

我正在使用 swagger 来记录使用 Laravel 5.8 构建的 API 应用程序。我还在使用 Passport 进行 API 身份验证,并尝试在文档中实现它。

当我尝试在 swagger 上授权用户时,我在此处收到错误

auth errorTypeError:尝试获取资源时出现网络错误。

这就是我如何设置它

l5-swagger.php配置文件中

/* Open API 3.0 support */
'passport' => [ // Unique name of security
    'type' => 'oauth2', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
    'description' => 'Laravel passport oauth2 security.',
    'in' => 'header',
    'scheme' => 'https',
    'flows' => [
        "password" => [
            "authorizationUrl" => config('app.url') . '/oauth/authorize',
            "tokenUrl" => config('app.url') . '/oauth/token',
            "refreshUrl" => config('app.url') . '/token/refresh',
            "scopes" => []
        ],
    ],
],

在控制器中,我有招摇的代码

/**
* @OA\Get(
*      path="/products/{product}",
*      tags={"Product"},
*      description="Gets specified product",
*      operationId="getProductById",
*      summary="Fetches a product by the product Id",
*      security={{"passport": {}}},
*      @OA\Parameter(...),
*      @OA\Response(...),
* )
*/

这是招摇授权屏幕的图像

https://i.stack.imgur.com/aiYjs.png

我从桌子上得到client_id& 。client_secretoauth_clients

身份验证是如何完成的,我有什么不同的做法?

标签: phplaravelswaggerlaravel-passport

解决方案


推荐阅读