Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

elo's avatar
Level 3

Working with Passport and Swagger for API documentation

Hi guys, I am using swagger for the documentation of an API application built using Laravel 5.8. I am also using Passport for the API authentication and tried implementing it in the documentation.

When I try to authorize a user on swagger, I get the error here

auth errorTypeError: NetworkError when attempting to fetch resource.

Here's how I have set it up swagger up

In l5-swagger.php config file

/* 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" => []
        ],
    ],
],

In the controller I have the swagger code

/**
* @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(...),
* )
*/

This is the image of swagger authorization screen

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

I get the client_id & client_secret from the oauth_clients table.

What am I doing wrong?

0 likes
2 replies
bilalameen's avatar

I had the same problem, I found the solution to change the passport type oauth2 to apiKey in the l5-swagger.php config file, and it all set for me

Please or to participate in this conversation.